Struct OrderedPoolAllocator

Source
pub struct OrderedPoolAllocator<'buf, T, const N: usize = { mem::size_of::<usize>() }> { /* private fields */ }
Expand description

An allocator for T objects, with a block index of N bytes.

Implementations§

Source§

impl<'buf, T, const N: usize> OrderedPoolAllocator<'buf, T, N>

Source

pub fn new_in(buf: &'buf mut [u8]) -> Self

Source

pub unsafe fn allocate(&mut self) -> Result<NonNull<T>, AllocError>

Allocates a block and returns a pointer to the block.

This method will always prioritize reallocating an existing deallocated block over allocating a new block.

§Safety

Behavior is undefined if the returned pointer points to an uninitialized instance of T when the allocator is dropped.

Source

pub unsafe fn deallocate(&mut self, ptr: NonNull<T>)

Deallocates the block at the specified pointer.

Side effect: swaps the virtual block indices of the specified block with the last allocated virtual block.

§Safety

Behavior is undefined if any of the following conditions are violated:

  • ptr must point to an instance of T allocated by this allocator.
  • ptr must not point to an instance of T that has already been dropped or deallocated by this allocator.
Source

pub const fn len(&self) -> usize

Source

pub const fn capacity(&self) -> usize

Source

pub const fn is_empty(&self) -> bool

Source

pub const fn is_full(&self) -> bool

Source

pub fn sort_unstable_by<F>(&mut self, compare: F)
where F: FnMut(&MaybeUninit<T>, &MaybeUninit<T>) -> Ordering,

Trait Implementations§

Source§

impl<T, const N: usize> Drop for OrderedPoolAllocator<'_, T, N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, const N: usize> Index<usize> for OrderedPoolAllocator<'_, T, N>

Source§

type Output = MaybeUninit<T>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, const N: usize> IndexMut<usize> for OrderedPoolAllocator<'_, T, N>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<'buf, T, const N: usize> Freeze for OrderedPoolAllocator<'buf, T, N>

§

impl<'buf, T, const N: usize> RefUnwindSafe for OrderedPoolAllocator<'buf, T, N>
where T: RefUnwindSafe,

§

impl<'buf, T, const N: usize = { mem::size_of::<usize>() }> !Send for OrderedPoolAllocator<'buf, T, N>

§

impl<'buf, T, const N: usize = { mem::size_of::<usize>() }> !Sync for OrderedPoolAllocator<'buf, T, N>

§

impl<'buf, T, const N: usize> Unpin for OrderedPoolAllocator<'buf, T, N>

§

impl<'buf, T, const N: usize> UnwindSafe for OrderedPoolAllocator<'buf, T, N>
where T: RefUnwindSafe,

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