Struct option_block::Block128
source · [−]pub struct Block128<T> { /* private fields */ }Expand description
A fixed block of optionals masked by a u128,
which may thus contain at most 128 elements.
Implementations
sourceimpl<T> Block128<T>
impl<T> Block128<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).
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 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
also 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.
pub fn iter(&self) -> Block128Iter<'_, T>ⓘNotable traits for Block128Iter<'a, T>impl<'a, T> Iterator for Block128Iter<'a, T> type Item = &'a T;
sourceimpl<T: Default> Block128<T>
impl<T: Default> Block128<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
sourceimpl<T: Clone> Clone for Block128<T>
impl<T: Clone> Clone for Block128<T>
Since the current implementation relies on MaybeUninit, the
block can only be cloned if the internal data is trivially copyable (bitwise).
It is necessary that the type does not implement Drop.
sourceimpl<T> Drop for Block128<T>
impl<T> Drop for Block128<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.
sourceimpl<T> FromIterator<(usize, T)> for Block128<T>
impl<T> FromIterator<(usize, T)> for Block128<T>
sourcefn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (usize, T)>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (usize, T)>,
Creates a value from an iterator. Read more
sourceimpl<T> IntoIterator for Block128<T>
impl<T> IntoIterator for Block128<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Block128<T> where
T: RefUnwindSafe,
impl<T> Send for Block128<T> where
T: Send,
impl<T> Sync for Block128<T> where
T: Sync,
impl<T> Unpin for Block128<T> where
T: Unpin,
impl<T> UnwindSafe for Block128<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more