Struct simple_chunk_allocator::AllocatorApiGlue
source · [−]pub struct AllocatorApiGlue<'a, 'b, const CHUNK_SIZE: usize>(_);
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
sourceimpl<'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>
sourcefn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)Attempts to allocate a block of memory. Read more
sourceunsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
allocator_api
)Deallocates the memory referenced by ptr
. Read more
sourcefn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)Behaves like allocate
, but also ensures that the returned memory is zero-initialized. Read more
sourceunsafe 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>
allocator_api
)Attempts to extend the memory block. Read more
sourceunsafe 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>
allocator_api
)Behaves like grow
, but also ensures that the new contents are set to zero before being
returned. Read more
Auto Trait Implementations
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> where
'b: 'a,
impl<'a, 'b, const CHUNK_SIZE: usize> !UnwindSafe for AllocatorApiGlue<'a, 'b, CHUNK_SIZE>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more