pub trait Allocator: Clone {
// Required methods
fn alloc(&self, layout: Layout) -> Result<GlobalPtr<u8>, AllocError>;
unsafe fn dealloc(&self, ptr: GlobalPtr<u8>, layout: Layout);
// Provided methods
fn alloc_with<T>(
&self,
f: impl FnOnce(RefMut<'_, MaybeUninit<T>>) -> Result<RefMut<'_, T>, AllocError>,
) -> Result<GlobalPtr<u8>, AllocError> { ... }
unsafe fn realloc(
&self,
ptr: GlobalPtr<u8>,
layout: Layout,
newsize: usize,
) -> Result<GlobalPtr<u8>, AllocError> { ... }
}
Expand description
Basic allocation trait.
Required Methods§
Sourcefn alloc(&self, layout: Layout) -> Result<GlobalPtr<u8>, AllocError>
fn alloc(&self, layout: Layout) -> Result<GlobalPtr<u8>, AllocError>
Allocate based on layout within this allocator. Returns a global pointer to the start of the allocation.
Note: Using this function by itself can leak memory, particularly on failure. Users should consider using InvBox instead.
Provided Methods§
Sourcefn alloc_with<T>(
&self,
f: impl FnOnce(RefMut<'_, MaybeUninit<T>>) -> Result<RefMut<'_, T>, AllocError>,
) -> Result<GlobalPtr<u8>, AllocError>
fn alloc_with<T>( &self, f: impl FnOnce(RefMut<'_, MaybeUninit<T>>) -> Result<RefMut<'_, T>, AllocError>, ) -> Result<GlobalPtr<u8>, AllocError>
Allocate based on layout within this allocator. Returns a global pointer to the start of the allocation.
Note: Using this function by itself can leak memory, particularly on failure. Users should consider using InvBox instead.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.