所以基本上我正在制作一个需要成员可变的结构,因为同一个成员将被另一个将改变它的函数借用,如下所示:
fn chunk(&mut self) -> gdnative::Ref<ArrayMesh>{
let st = SurfaceTool::new();
// st.begin(Mesh::PRIMITIVE_TRIANGLES);
st.begin(Mesh::PRIMITIVE_LInes);
for x in 0..self.size.0{
for y in 0..self.size.1{
for z in 0..self.size.2{
VoxelChunk::custom_voxel(
&st,Vector3::new(x as f32 + self.pos.x,y as f32 + self.pos.y,z as f32 + self.pos.z),&self.data
);
}
}
}
st.generate_normals(false);
let mesh: Ref<ArrayMesh> = st.commit(gdnative::Null::null(),Mesh::ARRAY_COMPRESS_DEFAULT).unwrap();
godot_print!("commited mesh!");
return mesh;
}
功能:
fn custom_voxel(st:&Ref<SurfaceTool,Unique>,pos:Vector3,data: &mut Vec<u8>){
//it has a lot of stuff so im not gonna put in here
}
它给了我这个,但我不知道如何使该成员成为可变引用
error[E0308]: mismatched types
--> src/lib.rs:114:7
|
114 | &self.data
| ^^^^^^^^^^ types differ in mutability
|
= note: expected mutable reference `&mut Vec<u8>`
found reference `&Vec<u8>`
error: aborting due to previous error; 1 warning emitted
For more information about this error,try `rustc --explain E0308`.