如何解决Rust - 结构体可以有可变成员吗?
所以基本上我正在制作一个需要成员可变的结构,因为同一个成员将被另一个将改变它的函数借用,如下所示:
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`.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。