pub trait AllocationController {
// Required methods
fn alloc_align(&self) -> usize;
fn property(&self) -> AllocationProperty;
unsafe fn memory_mut(&mut self) -> &mut [MaybeUninit<u8>];
fn memory(&self) -> &[MaybeUninit<u8>];
// Provided methods
fn split(
&mut self,
_offset: usize,
) -> Result<(Box<dyn AllocationController>, Box<dyn AllocationController>), SplitError> { ... }
fn duplicate(&self) -> Option<Box<dyn AllocationController>> { ... }
unsafe fn copy_into(&self, buf: &mut [u8]) { ... }
fn grow(&mut self, size: usize, align: usize) -> Result<(), AllocationError> { ... }
fn try_detach(&mut self) -> Option<NonNull<u8>> { ... }
}Expand description
Defines how an [Allocation] can be controlled.
This trait enables type erasure of the allocator after an [Allocation] is created, while still providing methods to modify or manage an existing [Allocation].
Required Methods§
Sourcefn alloc_align(&self) -> usize
fn alloc_align(&self) -> usize
The alignment this allocation was created with.
Sourcefn property(&self) -> AllocationProperty
fn property(&self) -> AllocationProperty
Returns memory property for the current allocation.
Sourceunsafe fn memory_mut(&mut self) -> &mut [MaybeUninit<u8>]
unsafe fn memory_mut(&mut self) -> &mut [MaybeUninit<u8>]
Returns a mutable view of the memory of the whole allocation
§Safety
Must only write initialized data to the buffer.
Sourcefn memory(&self) -> &[MaybeUninit<u8>]
fn memory(&self) -> &[MaybeUninit<u8>]
Returns a view of the memory of the whole allocation
Provided Methods§
Sourcefn split(
&mut self,
_offset: usize,
) -> Result<(Box<dyn AllocationController>, Box<dyn AllocationController>), SplitError>
fn split( &mut self, _offset: usize, ) -> Result<(Box<dyn AllocationController>, Box<dyn AllocationController>), SplitError>
Splits the current allocation in multiple separate allocations.
Sourcefn duplicate(&self) -> Option<Box<dyn AllocationController>>
fn duplicate(&self) -> Option<Box<dyn AllocationController>>
Duplicates the current allocation with a clone on write strategy if the allocation controller supports it.
Sourceunsafe fn copy_into(&self, buf: &mut [u8])
unsafe fn copy_into(&self, buf: &mut [u8])
Reads the data from the current allocation controller and copy its content into the provided buffer.
§Safety
Ensures the length provided reflect initialized values in the current allocation controller.
Sourcefn grow(&mut self, size: usize, align: usize) -> Result<(), AllocationError>
fn grow(&mut self, size: usize, align: usize) -> Result<(), AllocationError>
Extends the provided [Allocation] to a new size with specified alignment.
§Errors
Returns an AllocationError if the extension fails (e.g., due to insufficient memory or unsupported operation by the allocator).
Sourcefn try_detach(&mut self) -> Option<NonNull<u8>>
fn try_detach(&mut self) -> Option<NonNull<u8>>
Indicates whether the allocation uses the Rust alloc crate and can be safely managed by another data structure.
If true, the allocation is not managed by a memory pool and can be safely deallocated
using the alloc crate.
§Notes
This allows the allocation’s pointer to be converted into a native Rust Vec without
requiring a new allocation.
Implementing this incorrectly is unsafe and may lead to undefined behavior.