pub struct Storage<T, I: TypedId> {
pub(crate) map: Vec<Element<T>>,
pub(crate) kind: &'static str,
pub(crate) _phantom: PhantomData<I>,
}
Expand description
A table of T
values indexed by the id type I
.
The table is represented as a vector indexed by the ids’ index
values, so you should use an id allocator like IdentityManager
that keeps the index values dense and close to zero.
Fields§
§map: Vec<Element<T>>
§kind: &'static str
§_phantom: PhantomData<I>
Implementations§
source§impl<T, I: TypedId> Storage<T, I>
impl<T, I: TypedId> Storage<T, I>
pub(crate) fn contains(&self, id: I) -> bool
sourcepub(crate) fn try_get(&self, id: I) -> Result<Option<&T>, InvalidId>
pub(crate) fn try_get(&self, id: I) -> Result<Option<&T>, InvalidId>
Attempts to get a reference to an item behind a potentially invalid ID.
Returns None
if there is an epoch mismatch, or the entry is empty.
This function is primarily intended for the as_hal
family of functions
where you may need to fallibly get a object backed by an id that could
be in a different hub.
sourcepub(crate) fn get(&self, id: I) -> Result<&T, InvalidId>
pub(crate) fn get(&self, id: I) -> Result<&T, InvalidId>
Get a reference to an item behind a potentially invalid ID. Panics if there is an epoch mismatch, or the entry is empty.
sourcepub(crate) fn get_mut(&mut self, id: I) -> Result<&mut T, InvalidId>
pub(crate) fn get_mut(&mut self, id: I) -> Result<&mut T, InvalidId>
Get a mutable reference to an item behind a potentially invalid ID. Panics if there is an epoch mismatch, or the entry is empty.