simple_chunk_allocator

Struct AllocatorApiGlue

source
pub struct AllocatorApiGlue<'a, 'b, const CHUNK_SIZE: usize>(/* private fields */);
Expand description

Helper struct generated by GlobalChunkAllocator that can be used in structs that accept a custom instance of a specific allocator implementation.

This is mainly relevant for testing the allocator. In a real environment, an instance of GlobalChunkAllocator is likely registered a global allocator for Rust. Thus, Vec and others default to the Global allocator, which will use GlobalChunkAllocator.

§Example

// ...

// Vector from the standard library will use my custom allocator instead.
let vec = Vec::<u8, _>::with_capacity_in(123, ALLOCATOR.allocator_api_glue());

Trait Implementations§

source§

impl<'a, 'b, const CHUNK_SIZE: usize> Allocator for AllocatorApiGlue<'a, 'b, CHUNK_SIZE>

source§

fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>

🔬This is a nightly-only experimental API. (allocator_api)
Attempts to allocate a block of memory. Read more
source§

unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)

🔬This is a nightly-only experimental API. (allocator_api)
Deallocates the memory referenced by ptr. Read more
source§

unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>

🔬This is a nightly-only experimental API. (allocator_api)
Attempts to extend the memory block. Read more
source§

fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>

🔬This is a nightly-only experimental API. (allocator_api)
Behaves like allocate, but also ensures that the returned memory is zero-initialized. Read more
source§

unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>

🔬This is a nightly-only experimental API. (allocator_api)
Behaves like grow, but also ensures that the new contents are set to zero before being returned. Read more
source§

unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>

🔬This is a nightly-only experimental API. (allocator_api)
Attempts to shrink the memory block. Read more
source§

fn by_ref(&self) -> &Self
where Self: Sized,

🔬This is a nightly-only experimental API. (allocator_api)
Creates a “by reference” adapter for this instance of Allocator. Read more
source§

impl<'a, 'b, const CHUNK_SIZE: usize> Debug for AllocatorApiGlue<'a, 'b, CHUNK_SIZE>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, 'b, const CHUNK_SIZE: usize> Freeze for AllocatorApiGlue<'a, 'b, CHUNK_SIZE>

§

impl<'a, 'b, const CHUNK_SIZE: usize> !RefUnwindSafe for AllocatorApiGlue<'a, 'b, CHUNK_SIZE>

§

impl<'a, 'b, const CHUNK_SIZE: usize> Send for AllocatorApiGlue<'a, 'b, CHUNK_SIZE>

§

impl<'a, 'b, const CHUNK_SIZE: usize> Sync for AllocatorApiGlue<'a, 'b, CHUNK_SIZE>

§

impl<'a, 'b, const CHUNK_SIZE: usize> Unpin for AllocatorApiGlue<'a, 'b, CHUNK_SIZE>

§

impl<'a, 'b, const CHUNK_SIZE: usize> !UnwindSafe for AllocatorApiGlue<'a, 'b, CHUNK_SIZE>

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.