pub(crate) struct HandleVec<T, U> {
inner: Vec<U>,
as_keys: PhantomData<T>,
}
Expand description
A HandleVec<T, U>
is a Vec<U>
indexed by values of type Handle<T>
,
rather than usize
.
Rather than a push
method, HandleVec
has an insert
method, analogous
to HashMap::insert
, that requires you to provide the handle at which the
new value should appear. However, since HandleVec
only supports insertion
at the end, the given handle’s index must be equal to the the HandleVec
’s
current length; otherwise, the insertion will panic.
Fields§
§inner: Vec<U>
§as_keys: PhantomData<T>
Implementations§
source§impl<T, U> HandleVec<T, U>
impl<T, U> HandleVec<T, U>
pub(crate) const fn new() -> Self
pub(crate) fn with_capacity(capacity: usize) -> Self
pub(crate) fn len(&self) -> usize
sourcepub(crate) fn insert(&mut self, handle: Handle<T>, value: U)
pub(crate) fn insert(&mut self, handle: Handle<T>, value: U)
Insert a mapping from handle
to value
.
Unlike a HashMap
, a HandleVec
can only have new entries inserted at
the end, like Vec::push
. So the index of handle
must equal
self.len()
.
pub(crate) fn get(&self, handle: Handle<T>) -> Option<&U>
pub(crate) fn clear(&mut self)
pub(crate) fn resize(&mut self, len: usize, fill: U)where
U: Clone,
pub(crate) fn iter(&self) -> impl Iterator<Item = &U>
pub(crate) fn iter_mut(&mut self) -> impl Iterator<Item = &mut U>
Trait Implementations§
Auto Trait Implementations§
impl<T, U> Freeze for HandleVec<T, U>
impl<T, U> RefUnwindSafe for HandleVec<T, U>where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for HandleVec<T, U>
impl<T, U> Sync for HandleVec<T, U>
impl<T, U> Unpin for HandleVec<T, U>
impl<T, U> UnwindSafe for HandleVec<T, U>where
T: UnwindSafe,
U: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more