I have the following snippet of code:
let mut scene = Scene::new(32);
let mut entity_id = scene.create_entity();
{
let mut e = scene.get_entity(entity_id);
let mut ic = ImageComponent::new();
ic.texture = Some(tm.get(&String::from("wabbit")));
match e {
Some(entity) => {
entity.add(Rc::new(ic));
},
None => {
sdl2::log::log("Something went wrong with the entity")
},
}
}
The signature for get_entity
is the following:
pub fn get_entity(&self, entity_id: u32) -> Option<&Entity>
I thought that I would just get that Option<&Entity>
object, match it and call it's add
function that has the following signature:
pub fn add(&mut self, component: Rc<Component>)
but it looks like entity
is immutable and I cannot borrow it as mutable.
The actual error is the following:
error[E0596]: cannot borrow immutable borrowed content `*entity` as mutable
--> src/engine.rs:350:21
|
350 | entity.add(Rc::new(ic));
| ^^^^^^ cannot borrow as mutable
error: aborting due to previous error
Any help is kindly appreciated