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§
Required Methods§
Sourceunsafe fn set_length(&mut self, len: Self::Index)
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.
Sourcefn grow_buffer(
&mut self,
capacity: Self::Index,
exact: bool,
) -> Result<(), StorageError>
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.
Sourcefn shrink_buffer(&mut self, capacity: Self::Index) -> Result<(), StorageError>
fn shrink_buffer(&mut self, capacity: Self::Index) -> Result<(), StorageError>
Attempt to resize this buffer to a new, smaller capacity.
Provided Methods§
Sourcefn as_uninit_slice(&mut self) -> &mut [MaybeUninit<Self::Item>]
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()
.
Sourcefn as_slice(&self) -> &[Self::Item]
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()
.
Sourcefn as_mut_slice(&mut self) -> &mut [Self::Item]
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()
.
Sourceunsafe fn uninit_index(&mut self, index: usize) -> &mut MaybeUninit<Self::Item>
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.