flex_alloc::vec::buffer

Trait VecBuffer

Source
pub trait VecBuffer: RawBuffer<RawData = Self::Item> {
    type Item;
    type Index: Index;

    // Required methods
    fn capacity(&self) -> Self::Index;
    fn length(&self) -> Self::Index;
    unsafe fn set_length(&mut self, len: Self::Index);
    fn grow_buffer(
        &mut self,
        capacity: Self::Index,
        exact: bool,
    ) -> Result<(), StorageError>;
    fn shrink_buffer(
        &mut self,
        capacity: Self::Index,
    ) -> Result<(), StorageError>;

    // Provided methods
    fn as_uninit_slice(&mut self) -> &mut [MaybeUninit<Self::Item>] { ... }
    fn as_slice(&self) -> &[Self::Item] { ... }
    fn as_mut_slice(&mut self) -> &mut [Self::Item] { ... }
    unsafe fn uninit_index(
        &mut self,
        index: usize,
    ) -> &mut MaybeUninit<Self::Item> { ... }
}
Expand description

A concrete Vec backing buffer.

Required Associated Types§

Source

type Item

The type of the items stored in the Vec.

Source

type Index: Index

The index type used to store the capacity and length.

Required Methods§

Source

fn capacity(&self) -> Self::Index

Access the capacity of the buffer.

Source

fn length(&self) -> Self::Index

Access the number of items stored in the buffer.

Source

unsafe fn set_length(&mut self, len: Self::Index)

Set the current length of the buffer.

§Safety

A zero length buffer may not have an active allocation, and so it is undefined behavior to set its length, even if setting it to zero. Doing so may produce invalid memory access errors.

Source

fn grow_buffer( &mut self, capacity: Self::Index, exact: bool, ) -> Result<(), StorageError>

Attempt to resize this buffer to a new capacity. The exact flag determines whether a larger capacity would be acceptable.

Source

fn shrink_buffer(&mut self, capacity: Self::Index) -> Result<(), StorageError>

Attempt to resize this buffer to a new, smaller capacity.

Provided Methods§

Source

fn as_uninit_slice(&mut self) -> &mut [MaybeUninit<Self::Item>]

Access the contiguous memory contained in this buffer as a slice of MaybeUnint<Self::Item>. The length of this slice must correspond to self.capacity().

Source

fn as_slice(&self) -> &[Self::Item]

Access the items contained in this buffer as a slice of Self::Item. The length of this slice must correspond to self.length().

Source

fn as_mut_slice(&mut self) -> &mut [Self::Item]

Access the items contained in this buffer as a mutable slice of Self::Item. The length of this slice must correspond to self.length().

Source

unsafe fn uninit_index(&mut self, index: usize) -> &mut MaybeUninit<Self::Item>

Access an index of the buffer as a mutable reference to a MaybeUninit<Self::Item>.

§Safety

The index must be within the bounds of the buffer’s capacity, otherwise a memory access error may occur.

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.

Implementors§

Source§

impl<'a, T: 'a, const N: usize> VecBuffer for InlineBuffer<T, N>

Source§

impl<T, I: Index, A: Allocator> VecBuffer for FatBuffer<T, VecHeader<I>, A>

Source§

type Item = T

Source§

type Index = I

Source§

impl<T, I: Index, A: Allocator> VecBuffer for ThinBuffer<T, VecHeader<I>, A>

Source§

type Item = T

Source§

type Index = I