Trait GrowableSlab

pub trait GrowableSlab: Slab {
    // Required methods
    fn capacity(&self) -> usize;
    fn reserve_capacity(&mut self, capacity: usize);
    fn increment_len(&mut self, n: usize) -> usize;

    // Provided methods
    fn maybe_expand_to_fit<T>(&mut self, len: usize)
       where T: SlabItem { ... }
    fn allocate<T>(&mut self) -> Id<T>
       where T: SlabItem { ... }
    fn allocate_array<T>(&mut self, len: usize) -> Array<T>
       where T: SlabItem { ... }
    fn append<T>(&mut self, t: &T) -> Id<T>
       where T: SlabItem { ... }
    fn append_array<T>(&mut self, ts: &[T]) -> Array<T>
       where T: SlabItem { ... }
}
Expand description

Trait for slabs of u32s that can store many types, and can grow to fit.

Required Methods§

fn capacity(&self) -> usize

Return the current capacity of the slab.

fn reserve_capacity(&mut self, capacity: usize)

Reserve enough space on the slab to fit the given capacity.

fn increment_len(&mut self, n: usize) -> usize

Increment the length of the slab by n u32s.

Returns the previous length.

Provided Methods§

fn maybe_expand_to_fit<T>(&mut self, len: usize)
where T: SlabItem,

Expands the slab to fit the given number of Ts, if necessary.

fn allocate<T>(&mut self) -> Id<T>
where T: SlabItem,

Preallocate space for one T element, but don’t write anything to the buffer.

The returned Id can be used to write later with Slab::write.

NOTE: This changes the next available buffer index and may change the buffer capacity.

fn allocate_array<T>(&mut self, len: usize) -> Array<T>
where T: SlabItem,

Preallocate space for len T elements, but don’t write to the buffer.

This can be used to allocate space for a bunch of elements that get written later with Slab::write_array.

NOTE: This changes the length of the buffer and may change the capacity.

fn append<T>(&mut self, t: &T) -> Id<T>
where T: SlabItem,

Append to the end of the buffer.

Returns the Id of the written element.

fn append_array<T>(&mut self, ts: &[T]) -> Array<T>
where T: SlabItem,

Append a slice to the end of the buffer, resizing if necessary and returning a slabbed array.

Returns the Array of the written elements.

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§

§

impl GrowableSlab for Vec<u32>

§

fn capacity(&self) -> usize

§

fn reserve_capacity(&mut self, capacity: usize)

§

fn increment_len(&mut self, n: usize) -> usize

Implementors§

§

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