Trait Slab
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 is_empty(&self) -> bool { ... }
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_into_if_some<T>(&self, id: Id<T>, t: &mut T)
where T: SlabItem { ... }
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 u32
s that can store many types.
Required Methods§
fn read_unchecked<T>(&self, id: Id<T>) -> Twhere
T: SlabItem,
fn read_unchecked<T>(&self, id: Id<T>) -> Twhere
T: SlabItem,
Read the type from the slab using the Id
as the index.
fn write_indexed<T>(&mut self, t: &T, index: usize) -> usizewhere
T: SlabItem,
fn write_indexed<T>(&mut self, t: &T, index: usize) -> usizewhere
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.
fn write_indexed_slice<T>(&mut self, t: &[T], index: usize) -> usizewhere
T: SlabItem,
fn write_indexed_slice<T>(&mut self, t: &[T], index: usize) -> usizewhere
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§
fn is_empty(&self) -> bool
fn contains<T>(&self, id: Id<T>) -> boolwhere
T: SlabItem,
fn contains<T>(&self, id: Id<T>) -> boolwhere
T: SlabItem,
Returns true
if the slab size is great enough to contain the value with the given id.
fn read<T>(&self, id: Id<T>) -> T
fn read<T>(&self, id: Id<T>) -> T
Read the type from the slab using the Id
as the index, or return
the default if id
is Id::NONE
.
fn read_into_if_some<T>(&self, id: Id<T>, t: &mut T)where
T: SlabItem,
fn read_vec<T>(&self, array: Array<T>) -> Vec<T>
fn write<T>(&mut self, id: Id<T>, t: &T)where
T: SlabItem,
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.
fn write_array<T>(&mut self, array: Array<T>, data: &[T])where
T: SlabItem,
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.