pub trait Memory{
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§
Sourcefn as_mut_ptr(&mut self) -> *mut u8
fn as_mut_ptr(&mut self) -> *mut u8
Returns an unsafe mutable pointer to the memory’s buffer.
Sourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the number of elements in the memory, also referred to as its ‘length’.
Sourcefn len_mut(&mut self) -> &mut usize
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.
Sourcefn reserve(&mut self, capacity: usize) -> Result<(), Self::Error>
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.
Provided Methods§
Sourceunsafe fn try_into_memvec<'a, T: Copy>(
self,
) -> Result<MemVec<'a, T, Self>, (Self, MemoryLayoutError)>where
Self: Sized,
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.