Struct wasmtime_slab::Slab

source ·
pub struct Slab<T> { /* private fields */ }
Expand description

A simple, uni-typed slab arena.

Implementations§

source§

impl<T> Slab<T>

source

pub const MAX_CAPACITY: usize = 4_294_967_294usize

The maximum capacity any Slab can have: u32::MAX - 1.

source

pub fn new() -> Self

Construct a new, empty slab.

source

pub fn with_capacity(capacity: usize) -> Self

Construct a new, empty slab, pre-reserving space for at least capacity elements.

source

pub fn reserve(&mut self, additional: usize)

Ensure that there is space for at least additional elements in this slab.

§Panics

Panics if the new capacity exceeds Self::MAX_CAPACITY.

source

pub fn capacity(&self) -> usize

What is the capacity of this slab? That is, how many entries can it contain within its current underlying storage?

source

pub fn len(&self) -> usize

How many values are currently allocated within this slab?

source

pub fn is_empty(&self) -> bool

Are there zero allocated values within this slab?

source

pub fn try_alloc(&mut self, value: T) -> Result<Id, T>

Try to allocate a T value within this slab.

If there is no available capacity, ownership of the given value is returned via Err(value).

source

pub fn alloc(&mut self, value: T) -> Id

Allocate a T value within this slab, allocating additional underlying storage if there is no available capacity.

§Panics

Panics if allocating this value requires reallocating the underlying storage, and the new capacity exceeds Slab::MAX_CAPACITY.

source

pub fn next_id(&self) -> Id

Get the Id that will be returned for the next allocation in this slab.

source

pub fn get(&self, id: Id) -> Option<&T>

Get a shared borrow of the value associated with id.

Returns None if the value has since been deallocated.

If id comes from a different Slab instance, this method may panic, return None, or return an arbitrary value.

source

pub fn get_mut(&mut self, id: Id) -> Option<&mut T>

Get an exclusive borrow of the value associated with id.

Returns None if the value has since been deallocated.

If id comes from a different Slab instance, this method may panic, return None, or return an arbitrary value.

source

pub fn contains(&self, id: Id) -> bool

Does this slab contain an allocated value for id?

source

pub fn dealloc(&mut self, id: Id) -> T

Deallocate the value associated with the given id.

If id comes from a different Slab instance, this method may panic or deallocate an arbitrary value.

source

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

Iterate over all values currently allocated within this Slab.

Yields pairs of an Id and the Id’s associated value.

Iteration order is undefined.

source

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

Mutably iterate over all values currently allocated within this Slab.

Yields pairs of an Id and the Id’s associated value.

Iteration order is undefined.

source

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

Iterate over and remove all entries in this slab.

The slab will be empty after calling this method.

Yields pairs of an Id and the Id’s associated value.

Iteration order is undefined.

Trait Implementations§

source§

impl<T> Debug for Slab<T>
where T: Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<T> Default for Slab<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> Index<Id> for Slab<T>

§

type Output = T

The returned type after indexing.
source§

fn index(&self, id: Id) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<T> IndexMut<Id> for Slab<T>

source§

fn index_mut(&mut self, id: Id) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Slab<T>

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Slab<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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.