LinkedSlab

Struct LinkedSlab 

Source
pub struct LinkedSlab<T> {
    entries: Vec<Entry<T>>,
    next_free: NonZeroU32,
}
Expand description

A slab like structure that also maintains circular lists with its items.

Fields§

§entries: Vec<Entry<T>>§next_free: NonZeroU32

Implementations§

Source§

impl<T> LinkedSlab<T>

Source

pub fn with_capacity(capacity: usize) -> Self

Source

pub fn insert(&mut self, item: T) -> NonZeroU32

Inserts a new entry in the list. Initially, the item will belong to a list only containing itself.

§Panics

Panics if number of items exceed u32::MAX - 1.

Source

pub fn get(&self, index: NonZeroU32) -> Option<(&T, NonZeroU32)>

Gets an entry and a token to the next entry.

Source

pub fn get_mut(&mut self, index: NonZeroU32) -> Option<(&mut T, NonZeroU32)>

Gets an entry and a token to the next entry.

Source

pub unsafe fn get_unchecked(&self, index: NonZeroU32) -> (&T, NonZeroU32)

Gets an entry and a token to the next entry w/o checking, thus unsafe.

Source

pub unsafe fn get_mut_unchecked( &mut self, index: NonZeroU32, ) -> (&mut T, NonZeroU32)

Gets an entry and a token to the next entry w/o checking, thus unsafe.

Links an entry before target_head. Returns the item next to the linked item, which is either the item itself or target_head.

§Panics

Panics on out of bounds access. Panics (in debug mode) if linking an absent entry.

Unlinks an entry without removing it from the ring Returns next item in the list, if not self.

§Panics

Panics on out of bounds access. Panics (in debug mode) if unlinking an absent entry.

Source

pub fn remove(&mut self, idx: NonZeroU32) -> Option<(T, Option<NonZeroU32>)>

Unlinks and removes the entry from the ring. Returns next item in the list, if not self.

§Panics

Panics on out of bounds access.

Source

pub fn next_free(&self) -> NonZeroU32

The Token that will be returned by the next call to insert()

Source

pub fn drain(&mut self) -> impl Iterator<Item = T> + '_

Drains all items from the slab.

The slab will be emptied even if the returned iterator isn’t fully consumed.

Source

pub fn iter(&self) -> impl Iterator<Item = &T> + '_

Iterator for the items in the slab

Source

pub fn iter_from( &self, continuation: Option<NonZeroU32>, ) -> impl Iterator<Item = (NonZeroU32, &T)> + '_

Iterator for the items in the slab, starting after a given token.

Source

pub fn memory_used(&self) -> usize

Get the memory used by LinkedSlab

It should be noted that if cache key or value is some type like Vec<T>, the memory allocated in the heap will not be counted.

Trait Implementations§

Source§

impl<T: Clone> Clone for LinkedSlab<T>

Source§

fn clone(&self) -> LinkedSlab<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for LinkedSlab<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for LinkedSlab<T>

§

impl<T> RefUnwindSafe for LinkedSlab<T>
where T: RefUnwindSafe,

§

impl<T> Send for LinkedSlab<T>
where T: Send,

§

impl<T> Sync for LinkedSlab<T>
where T: Sync,

§

impl<T> Unpin for LinkedSlab<T>
where T: Unpin,

§

impl<T> UnwindSafe for LinkedSlab<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.