Hey there!
I'm trying to do the following, have three structs, one which stores a vector of data, one which stores some metadata and a reference to the data struct, and a third one which manages these other two, such as:
pub struct GameModel {
vertices: Vec<Vec4>,
normals: Vec<Vec4>,
indices: Vec<(i32, i32, i32)>,
}
pub struct GameObject<'a> {
position: Vec3,
rot_x: f32,
rot_y: f32,
rot_z: f32,
size: f32,
model: &'a GameModel,
}
pub struct Scene<'b> {
models: HashMap<String,GameModel>,
objects: Vec<GameObject<'b>>
}
And in Scene's implementation I'd like to have a create_object function such as:
impl<'c> Scene<'c> {
.
.
.
pub fn create_object(&'c mut self, pos: Vec3, rot_x: f32, rot_y: f32, rot_z: f32, scale: f32, model: &str) {
if self.models.contains_key(model) {
self.objects.push(
GameObject::create(pos,rot_x,rot_y,rot_z,scale, self.models.get(model).unwrap())
);
}
}
}
The problem I'm running into is if i use this function, afterwards any function use which has "&mut self" in it throws an "cannot borrow scene
as mutable more than once at a time" error.
I'm guessing that this is probably a problem with my thinking, and this should probably be done in some other way in rust, but I'm not sure what that way is. Any help is appreciated.