wasmtime_slab

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

Source§

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

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.