pub unsafe trait AllocatorCore {
// Required methods
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocatorError>;
unsafe fn deallocate(&self, ptr: NonNull<[u8]>, layout: Layout);
}Expand description
A dynamic memory allocator for use with crate::alloc::Poly.
§Safety
Implementations must ensure that if allocate succeeds, the returned slice has a length
of at least layout.size() bytes and an alignment of at least layout.align(). If this
cannot be satisfied, then an error must be returned.
Required Methods§
Sourcefn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocatorError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocatorError>
Allocate space for at least layout.size() bytes aligned to at least
layout.align(). Returns an error if the requested size or alignment is not
possible with this allocator.
Sourceunsafe fn deallocate(&self, ptr: NonNull<[u8]>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<[u8]>, layout: Layout)
Deallocation companion to allocate.
§Safety
The caller must ensure that
ptris “currently allocated” from the allocator. See: https://doc.rust-lang.org/std/alloc/trait.Allocator.html#currently-allocated-memoryptrhas the same base pointer as the slice-pointer returned fromSelf::allocate.layoutis the same layout that was passed toSelf::allocatefor this pointer.