Struct ReusableMemory

Source
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>

Source

pub fn needed_capacity_for_two<T, U>( &self, capacity: [NonZeroUsize; 2], ) -> usize

Source

pub fn borrow_mut_two_as<'mem, T, U>( &'mem mut self, capacity: [NonZeroUsize; 2], ) -> (ReusableMemoryBorrow<'mem, T>, ReusableMemoryBorrow<'mem, U>)

Source

pub fn needed_capacity_for_three<T, U, V>( &self, capacity: [NonZeroUsize; 3], ) -> usize

Source

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>)

Source

pub fn needed_capacity_for_four<T, U, V, W>( &self, capacity: [NonZeroUsize; 4], ) -> usize

Source

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>)

Source

pub fn needed_capacity_for_five<T, U, V, W, X>( &self, capacity: [NonZeroUsize; 5], ) -> usize

Source

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>)

Source

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.
Source

pub fn new() -> Self

Panics if size_of::<B>() == 0

Source

pub fn with_capacity(len: usize) -> Self

Counted in the capacity of B.

Panics if size_of::<B>() == 0

Source

pub fn needed_capacity_for<T>(&self, count: NonZeroUsize) -> usize

Source

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>

Source§

fn clone(&self) -> ReusableMemory<B>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B: Debug> Debug for ReusableMemory<B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.