Slab

Trait Slab 

Source
pub trait Slab {
    // Required methods
    fn len(&self) -> usize;
    fn read_unchecked<T>(&self, id: Id<T>) -> T
       where T: SlabItem;
    fn write_indexed<T>(&mut self, t: &T, index: usize) -> usize
       where T: SlabItem;
    fn write_indexed_slice<T>(&mut self, t: &[T], index: usize) -> usize
       where T: SlabItem;

    // Provided methods
    fn contains<T>(&self, id: Id<T>) -> bool
       where T: SlabItem { ... }
    fn read<T>(&self, id: Id<T>) -> T
       where T: SlabItem + Default { ... }
    fn read_vec<T>(&self, array: Array<T>) -> Vec<T>
       where T: SlabItem + Default { ... }
    fn write<T>(&mut self, id: Id<T>, t: &T)
       where T: SlabItem { ... }
    fn write_array<T>(&mut self, array: Array<T>, data: &[T])
       where T: SlabItem { ... }
}
Expand description

Trait for slabs of u32s that can store many types.

Required Methodsยง

Source

fn len(&self) -> usize

Return the number of u32 elements in the slab.

Source

fn read_unchecked<T>(&self, id: Id<T>) -> T
where T: SlabItem,

Read the type from the slab using the Id as the index.

Source

fn write_indexed<T>(&mut self, t: &T, index: usize) -> usize
where T: SlabItem,

Write the type into the slab at the index.

Return the next index, or the same index if writing would overlap the slab.

Source

fn write_indexed_slice<T>(&mut self, t: &[T], index: usize) -> usize
where T: SlabItem,

Write a slice of the type into the slab at the index.

Return the next index, or the same index if writing would overlap the slab.

Provided Methodsยง

Source

fn contains<T>(&self, id: Id<T>) -> bool
where T: SlabItem,

Returns whether the slab may contain the value with the given id.

Source

fn read<T>(&self, id: Id<T>) -> T
where T: SlabItem + Default,

Read the type from the slab using the Id as the index, or return the default if id is Id::NONE.

Source

fn read_vec<T>(&self, array: Array<T>) -> Vec<T>
where T: SlabItem + Default,

Source

fn write<T>(&mut self, id: Id<T>, t: &T)
where T: SlabItem,

Write the type into the slab at the position of the given Id.

This likely performs a partial write if the given Id is out of bounds.

Source

fn write_array<T>(&mut self, array: Array<T>, data: &[T])
where T: SlabItem,

Write contiguous elements into the slab at the position of the given Array.

ยงNOTE

This does nothing if the length of Array is greater than the length of data.

Dyn Compatibilityยง

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Typesยง

Sourceยง

impl Slab for Vec<u32>

Available on non-target_arch=spirv only.
Sourceยง

fn len(&self) -> usize

Sourceยง

fn read_unchecked<T>(&self, id: Id<T>) -> T
where T: SlabItem,

Sourceยง

fn write_indexed<T>(&mut self, t: &T, index: usize) -> usize
where T: SlabItem,

Sourceยง

fn write_indexed_slice<T>(&mut self, t: &[T], index: usize) -> usize
where T: SlabItem,

Sourceยง

impl Slab for [u32]

Sourceยง

fn len(&self) -> usize

Sourceยง

fn read_unchecked<T>(&self, id: Id<T>) -> T
where T: SlabItem,

Sourceยง

fn write_indexed<T>(&mut self, t: &T, index: usize) -> usize
where T: SlabItem,

Sourceยง

fn write_indexed_slice<T>(&mut self, t: &[T], index: usize) -> usize
where T: SlabItem,

Implementorsยง

Sourceยง

impl<B> Slab for CpuSlab<B>
where B: Slab,