Memory

Trait Memory 

Source
pub trait Memory
where Self: Deref<Target = [u8]> + DerefMut<Target = [u8]>,
{ type Error: Debug; // Required methods fn as_ptr(&self) -> *const u8; fn as_mut_ptr(&mut self) -> *mut u8; fn len(&self) -> usize; fn len_mut(&mut self) -> &mut usize; fn reserve(&mut self, capacity: usize) -> Result<(), Self::Error>; fn shrink_to(&mut self, capacity: usize) -> Result<(), Self::Error>; // Provided method unsafe fn try_into_memvec<'a, T: Copy>( self, ) -> Result<MemVec<'a, T, Self>, (Self, MemoryLayoutError)> where Self: Sized { ... } }

Required Associated Types§

Required Methods§

Source

fn as_ptr(&self) -> *const u8

Returns a raw pointer to the memory’s buffer.

Source

fn as_mut_ptr(&mut self) -> *mut u8

Returns an unsafe mutable pointer to the memory’s buffer.

Source

fn len(&self) -> usize

Returns the number of elements in the memory, also referred to as its ‘length’.

Source

fn len_mut(&mut self) -> &mut usize

Returns a mutable reference to the length field for direct manipulation. This method is used when the length of Vec elements changes, such as with set_len.

Source

fn reserve(&mut self, capacity: usize) -> Result<(), Self::Error>

Reserves capacity for at least capacity bytes of data.

The allocator may reserve more space to speculatively avoid frequent allocations. After calling reserve, capacity will be greater than or equal to capacity. Does nothing if capacity is already sufficient.

Source

fn shrink_to(&mut self, capacity: usize) -> Result<(), Self::Error>

Shrinks the capacity of the memory as much as possible.

It will drop down as close as possible to the given capacity, but the allocator may still inform the memory that there is space for a few more elements.

Provided Methods§

Source

unsafe fn try_into_memvec<'a, T: Copy>( self, ) -> Result<MemVec<'a, T, Self>, (Self, MemoryLayoutError)>
where Self: Sized,

Create a MemVec object with memory.

§Safety

The memory must represent valid len and bytes representations of T.

Implementors§

Source§

impl Memory for MmapAnon
where Self: Deref<Target = [u8]> + DerefMut<Target = [u8]>,

Source§

impl<'a> Memory for MmapFile<'a>
where Self: Deref<Target = [u8]> + DerefMut<Target = [u8]>,

Source§

impl<'a> Memory for VecFile<'a>
where Self: Deref<Target = [u8]> + DerefMut<Target = [u8]>,