use crate::{ id::Id, storage::{Storage, StorageItem}, }; /// Registry is the primary holder of each resource type /// Every resource is now arcanized so the last arc released /// will in the end free the memory and release the inner raw resource /// /// Registry act as the main entry point to keep resource alive /// when created and released from user land code /// /// A resource may still be alive when released from user land code /// if it's used in active submission or anyway kept alive from /// any other dependent resource /// #[derive(Debug)] pub(crate) struct Registry { storage: Storage, } impl Registry { pub(crate) fn new() -> Self { Self { storage: Storage::new(), } } } impl Registry { pub(crate) fn assign(&mut self, id: Id, value: T) -> Id { self.storage.insert(id, value); id } pub(crate) fn remove(&mut self, id: Id) -> T { self.storage.remove(id) } } impl Registry { pub(crate) fn get(&self, id: Id) -> T { self.storage.get(id) } } impl Registry { pub(crate) fn get_mut(&mut self, id: Id) -> &mut T { self.storage.get_mut(id) } }