Skip to main content

Alloc

Struct Alloc 

Source
pub struct Alloc<T, A: Allocator> { /* private fields */ }
Expand description

Allocator-backed memory storage.

Wraps any Allocator to provide a RawMem implementation. Memory is freed and elements are dropped when the Alloc is dropped.

Implementations§

Source§

impl<T, A: Allocator> Alloc<T, A>

Source

pub const fn new(alloc: A) -> Self

Construct a new empty Alloc<T, A>. It will not allocate until growing.

// It's able to be static
static ALLOC: Global<()> = Global::new();

Trait Implementations§

Source§

impl<T, A: Allocator + Debug> Debug for Alloc<T, A>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T, A: Allocator> Drop for Alloc<T, A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, A: Allocator> RawMem for Alloc<T, A>

Source§

type Item = T

The element type stored in this memory.
Source§

fn allocated(&self) -> &[Self::Item]

Returns a shared slice of all currently initialized elements.
Source§

fn allocated_mut(&mut self) -> &mut [Self::Item]

Returns a mutable slice of all currently initialized elements.
Source§

unsafe fn grow( &mut self, addition: usize, fill: impl FnOnce(usize, (&mut [T], &mut [MaybeUninit<T>])), ) -> Result<&mut [T]>

Low-level growth: extends the memory by cap elements. Read more
Source§

fn shrink(&mut self, cap: usize) -> Result<()>

Removes the last cap elements, dropping them.
Source§

fn size_hint(&self) -> Option<usize>

Returns an optional hint about the total capacity, if known.
Source§

unsafe fn grow_assumed(&mut self, cap: usize) -> Result<&mut [Self::Item]>

grow which assumes that the memory is already initialized Read more
Source§

unsafe fn grow_zeroed(&mut self, cap: usize) -> Result<&mut [Self::Item]>

Safety Read more
Source§

unsafe fn grow_zeroed_exact(&mut self, cap: usize) -> Result<&mut [Self::Item]>

Safety Read more
Source§

fn grow_with( &mut self, addition: usize, f: impl FnMut() -> Self::Item, ) -> Result<&mut [Self::Item]>

Grows by addition elements, initializing each with the closure f.
Source§

unsafe fn grow_with_exact( &mut self, addition: usize, f: impl FnMut() -> Self::Item, ) -> Result<&mut [Self::Item]>

Safety Read more
Source§

fn grow_filled( &mut self, cap: usize, value: Self::Item, ) -> Result<&mut [Self::Item]>
where Self::Item: Clone,

Grows by cap elements, each cloned from value.
Source§

unsafe fn grow_filled_exact( &mut self, cap: usize, value: Self::Item, ) -> Result<&mut [Self::Item]>
where Self::Item: Clone,

Safety Read more
Source§

fn grow_within<R: RangeBounds<usize>>( &mut self, range: R, ) -> Result<&mut [Self::Item]>
where Self::Item: Clone,

Grows by cloning a sub-range of the currently allocated data.
Source§

fn grow_from_slice(&mut self, src: &[Self::Item]) -> Result<&mut [Self::Item]>
where Self::Item: Clone,

Grows by cloning all elements from src.

Auto Trait Implementations§

§

impl<T, A> Freeze for Alloc<T, A>
where A: Freeze,

§

impl<T, A> RefUnwindSafe for Alloc<T, A>

§

impl<T, A> Send for Alloc<T, A>
where A: Send, T: Send,

§

impl<T, A> Sync for Alloc<T, A>
where A: Sync, T: Sync,

§

impl<T, A> Unpin for Alloc<T, A>
where A: Unpin, T: Unpin,

§

impl<T, A> UnsafeUnpin for Alloc<T, A>
where A: UnsafeUnpin,

§

impl<T, A> UnwindSafe for Alloc<T, A>

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<All> ErasedMem for All
where All: RawMem + ?Sized,

Source§

type Item = <All as RawMem>::Item

The element type.
Source§

fn erased_allocated(&self) -> &[<All as ErasedMem>::Item]

Returns a shared slice of initialized elements (type-erased).
Source§

fn erased_allocated_mut(&mut self) -> &mut [<All as ErasedMem>::Item]

Returns a mutable slice of initialized elements (type-erased).
Source§

unsafe fn erased_grow( &mut self, cap: usize, fill: &mut dyn FillFn<<All as ErasedMem>::Item>, ) -> Result<&mut [<All as ErasedMem>::Item], Error>

Safety Read more
Source§

fn erased_shrink(&mut self, cap: usize) -> Result<(), Error>

Removes the last cap elements (type-erased).
Source§

fn erased_size_hint(&self) -> Option<usize>

Returns an optional capacity hint (type-erased).
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, 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.