pub struct ReusableMemory<B = u8> { /* private fields */ }
Expand description
Reusable memory struct.
This struct keeps previously allocated memory and can mutably reborrow it as a different type on demand.
The generic type B
can be used to control the alignment of the base memory, but it must not be zero sized.
Using a zero sized B
returns an error in constructor.
Implementations§
Source§impl<B> ReusableMemory<B>
impl<B> ReusableMemory<B>
pub fn needed_capacity_for_two<T, U>( &self, capacity: [NonZeroUsize; 2], ) -> usize
pub fn borrow_mut_two_as<'mem, T, U>( &'mem mut self, capacity: [NonZeroUsize; 2], ) -> (ReusableMemoryBorrow<'mem, T>, ReusableMemoryBorrow<'mem, U>)
pub fn needed_capacity_for_three<T, U, V>( &self, capacity: [NonZeroUsize; 3], ) -> usize
pub fn borrow_mut_three_as<'mem, T, U, V>( &'mem mut self, capacity: [NonZeroUsize; 3], ) -> (ReusableMemoryBorrow<'mem, T>, ReusableMemoryBorrow<'mem, U>, ReusableMemoryBorrow<'mem, V>)
pub fn needed_capacity_for_four<T, U, V, W>( &self, capacity: [NonZeroUsize; 4], ) -> usize
pub fn borrow_mut_four_as<'mem, T, U, V, W>( &'mem mut self, capacity: [NonZeroUsize; 4], ) -> (ReusableMemoryBorrow<'mem, T>, ReusableMemoryBorrow<'mem, U>, ReusableMemoryBorrow<'mem, V>, ReusableMemoryBorrow<'mem, W>)
pub fn needed_capacity_for_five<T, U, V, W, X>( &self, capacity: [NonZeroUsize; 5], ) -> usize
pub fn borrow_mut_five_as<'mem, T, U, V, W, X>( &'mem mut self, capacity: [NonZeroUsize; 5], ) -> (ReusableMemoryBorrow<'mem, T>, ReusableMemoryBorrow<'mem, U>, ReusableMemoryBorrow<'mem, V>, ReusableMemoryBorrow<'mem, W>, ReusableMemoryBorrow<'mem, X>)
Sourcepub const unsafe fn new_unchecked() -> Self
pub const unsafe fn new_unchecked() -> Self
Creates new reusable memory without checking the size of B
.
Can be used in const context.
§Safety
std::mem::size_of::<B>()
must not be zero.
Sourcepub fn with_capacity(len: usize) -> Self
pub fn with_capacity(len: usize) -> Self
Counted in the capacity of B
.
Panics if size_of::<B>() == 0
pub fn needed_capacity_for<T>(&self, count: NonZeroUsize) -> usize
Sourcepub fn borrow_mut_as<'mem, T>(
&'mem mut self,
capacity: NonZeroUsize,
) -> ReusableMemoryBorrow<'mem, T>
pub fn borrow_mut_as<'mem, T>( &'mem mut self, capacity: NonZeroUsize, ) -> ReusableMemoryBorrow<'mem, T>
Borrows the reusable memory as a different type.
This borrow is properly aligned and has at least the requested capacity.
Returns an error if size_of::<T>() == 0
.
Also returns an error when the pointer could not be aligned properly for T
.
Trait Implementations§
Source§impl<B: Clone> Clone for ReusableMemory<B>
impl<B: Clone> Clone for ReusableMemory<B>
Source§fn clone(&self) -> ReusableMemory<B>
fn clone(&self) -> ReusableMemory<B>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<B> Freeze for ReusableMemory<B>
impl<B> RefUnwindSafe for ReusableMemory<B>where
B: RefUnwindSafe,
impl<B> Send for ReusableMemory<B>where
B: Send,
impl<B> Sync for ReusableMemory<B>where
B: Sync,
impl<B> Unpin for ReusableMemory<B>where
B: Unpin,
impl<B> UnwindSafe for ReusableMemory<B>where
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more