I have an ecs system defined through these 2 objects:
pub struct ECStorage
{
pub(crate) entity_count : usize,
pub(crate) entity_components_map : BTreeMap<Entity, HashSet<TypeId>>,
pub(crate) components : BTreeMap<TypeId, Box<dyn Any>>,
}
pub(crate) struct ComponentStorage<T>
{
entity_component_map : BTreeMap<Entity, usize>,
components : Vec::<T>,
}
In this case the Any boxes in the ECS are all refcells of ComponentStorage.
I am running into an issue here:
pub fn component_query<T>(&mut self) -> std::slice::IterMut<T>
where T : 'static
{
let type_id = TypeId::of::<T>();
assert!(self.components.contains_key(&type_id));
let storage : &mut RefCell<ComponentStorage::<T>> =
self.components.get_mut(&type_id).unwrap().downcast_mut().unwrap();
storage.borrow_mut().components.iter_mut()
}
The borrow there is very short lived, so the iterator doesn't live long enough to allow me to return it. How do I specify that the borrow lasts as long as the scope of the caller?