pub struct Block16<T> { /* private fields */ }Expand description
A fixed block of optionals masked by a u16,
which may thus contain at most 16 elements.
Implementations§
Source§impl<T> Block16<T>
impl<T> Block16<T>
Sourcepub const fn is_vacant(&self, index: usize) -> bool
pub const fn is_vacant(&self, index: usize) -> bool
Checks whether the item at the index is vacant (i.e. contains None).
§Panic
Panics if index >= CAPACITY. See the maximum capacity.
Sourcepub const unsafe fn get_unchecked(&self, index: usize) -> &T
pub const unsafe fn get_unchecked(&self, index: usize) -> &T
Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Attempts to retrieve a shared reference to the element at index.
Returns None if the slot is vacant (i.e. uninitialized).
§Panic
Panics if index >= CAPACITY. See the maximum capacity.
Sourcepub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T
pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Attempts to retrieve an exclusive reference to the element at
index. Returns None if the slot is vacant (i.e. uninitialized).
§Panic
Panics if index >= CAPACITY. See the maximum capacity.
Sourcepub fn get_or_else(&mut self, index: usize, func: impl FnOnce() -> T) -> &mut T
pub fn get_or_else(&mut self, index: usize, func: impl FnOnce() -> T) -> &mut T
If the slot at the given index is already occupied, this method returns a mutable
reference to the inner data. Otherwise, if the slot is vacant, then this method
inserts the value constructed by func. A mutable reference to the inner data is
nevertheless returned.
Sourcepub fn get_or(&mut self, index: usize, val: T) -> &mut T
pub fn get_or(&mut self, index: usize, val: T) -> &mut T
Convenience wrapper for the get_or_else method.
Sourcepub fn insert(&mut self, index: usize, val: T) -> Option<T>
pub fn insert(&mut self, index: usize, val: T) -> Option<T>
Inserts the val at the index. If a value already exists, it returns Some
containing the old value. Otherwise, it returns None.
§Panic
Panics if index >= CAPACITY. See the maximum capacity.
Sourcepub fn remove(&mut self, index: usize) -> Option<T>
pub fn remove(&mut self, index: usize) -> Option<T>
Removes the value at the index. If a value already exists, it returns Some
containing that value. Otherwise, it returns None.
§Panic
Panics if index >= CAPACITY. See the maximum capacity.
Sourcepub fn iter(&self) -> Block16Iter<'_, T> ⓘ
pub fn iter(&self) -> Block16Iter<'_, T> ⓘ
Create a by-reference iterator for this block.
Source§impl<T: Default> Block16<T>
impl<T: Default> Block16<T>
Sourcepub fn get_or_default(&mut self, index: usize) -> &mut T
pub fn get_or_default(&mut self, index: usize) -> &mut T
Convenience wrapper for the get_or_else method.
Trait Implementations§
Source§impl<T> Drop for Block16<T>
Ensure that all remaining items in the block are dropped. Since the implementation
internally uses MaybeUninit, we must manually drop the valid
(i.e. initialized) contents ourselves.
impl<T> Drop for Block16<T>
Ensure that all remaining items in the block are dropped. Since the implementation
internally uses MaybeUninit, we must manually drop the valid
(i.e. initialized) contents ourselves.