[−][src]Struct slots::Slots
A type-checked slab allocator with predetermined size
The allocator deals out Key objects that can be used to access the data
later through a (shared or mutable) reference to the Slots. By the interface's design, access
is guaranteed to succeed, as the keys are unclonable and consumed to remove an item from the
Slots instance.
Methods
impl<IT, N> Slots<IT, N> where
N: ArrayLength<Entry<IT>> + Unsigned, [src]
N: ArrayLength<Entry<IT>> + Unsigned,
pub fn new() -> Self[src]
Create an empty slot allocator of size N.
If the verify_owner feature is enabled, it will carry a new unique (except for
wraparounds) ID which it shares with its keys.
pub fn capacity(&self) -> usize[src]
pub fn count(&self) -> usize[src]
pub fn store(&mut self, item: IT) -> Result<Key<IT, N>, IT>[src]
Put an item into a free slot
This returns an access index for the stored data in the success case, or hands the unstored item back in case of an error.
pub fn take(&mut self, key: Key<IT, N>) -> IT[src]
Move an item out of its slot
pub fn read<T, F>(&self, key: &Key<IT, N>, function: F) -> T where
F: FnOnce(&IT) -> T, [src]
F: FnOnce(&IT) -> T,
Provide immutable access to an item
pub fn try_read<T, F>(&self, index: usize, function: F) -> Option<T> where
F: FnOnce(&IT) -> T, [src]
F: FnOnce(&IT) -> T,
Opportunistic immutable access to an item by its index
A suitable index can be generated from a Key through its
index() method; unlike the regular access, this can fail if
the element has been removed (in which case the function is not run at all), or might have
been replaced by a completely unrelated element inbetween.
pub fn modify<T, F>(&mut self, key: &Key<IT, N>, function: F) -> T where
F: FnOnce(&mut IT) -> T, [src]
F: FnOnce(&mut IT) -> T,
Provide mutable access to an item
Auto Trait Implementations
impl<IT, N> Send for Slots<IT, N> where
IT: Send,
IT: Send,
impl<IT, N> Sync for Slots<IT, N> where
IT: Sync,
IT: Sync,
impl<IT, N> Unpin for Slots<IT, N> where
<N as ArrayLength<Entry<IT>>>::ArrayType: Unpin,
<N as ArrayLength<Entry<IT>>>::ArrayType: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,