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>
impl<'a, 'b, const CHUNK_SIZE: usize> Allocator for AllocatorApiGlue<'a, 'b, CHUNK_SIZE>
source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
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)
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 moresource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
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>
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 moresource§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
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 moreAuto 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> 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