pub unsafe trait Alloc<S>where
S: Size,{
// Required methods
fn alloc_range(
&self,
size: S,
len: usize,
) -> Result<PageRange<PAddr, S>, AllocError>;
fn dealloc_range(
&self,
range: PageRange<PAddr, S>,
) -> Result<(), AllocError>;
// Provided methods
fn alloc(&self, size: S) -> Result<Page<PAddr, S>, AllocError> { ... }
fn dealloc(&self, page: Page<PAddr, S>) -> Result<(), AllocError> { ... }
}Expand description
An allocator for physical pages of a given size.
§Safety
This trait is unsafe to implement, as implementations are responsible for guaranteeing that allocated pages are unique, and may not be allocated by another page allocator.
Required Methods§
Sourcefn alloc_range(
&self,
size: S,
len: usize,
) -> Result<PageRange<PAddr, S>, AllocError>
fn alloc_range( &self, size: S, len: usize, ) -> Result<PageRange<PAddr, S>, AllocError>
Allocate a range of len pages.
§Returns
Ok(PageRange)if a range of pages was successfully allocatedErrif the requested range could not be satisfied by this allocator.
Sourcefn dealloc_range(&self, range: PageRange<PAddr, S>) -> Result<(), AllocError>
fn dealloc_range(&self, range: PageRange<PAddr, S>) -> Result<(), AllocError>
Deallocate a range of pages.
§Returns
Ok(())if a range of pages was successfully deallocatedErrif the requested range could not be deallocated.
Provided Methods§
Sourcefn alloc(&self, size: S) -> Result<Page<PAddr, S>, AllocError>
fn alloc(&self, size: S) -> Result<Page<PAddr, S>, AllocError>
Allocate a single page.
Note that an implementation of this method is provided as long as an
implementor of this trait provides alloc_range.
§Returns
Ok(Page)if a page was successfully allocated.Errif no more pages can be allocated by this allocator.
Sourcefn dealloc(&self, page: Page<PAddr, S>) -> Result<(), AllocError>
fn dealloc(&self, page: Page<PAddr, S>) -> Result<(), AllocError>
Deallocate a single page.
Note that an implementation of this method is provided as long as an
implementor of this trait provides dealloc_range.
§Returns
Ok(())if the page was successfully deallocated.Errif the requested range could not be deallocated.
Implementations on Foreign Types§
Source§impl<S, const FREE_LISTS: usize> Alloc<S> for Alloc<FREE_LISTS>
impl<S, const FREE_LISTS: usize> Alloc<S> for Alloc<FREE_LISTS>
Source§fn alloc_range(
&self,
size: S,
len: usize,
) -> Result<PageRange<PAddr, S>, AllocError>
fn alloc_range( &self, size: S, len: usize, ) -> Result<PageRange<PAddr, S>, AllocError>
Allocate a range of at least len pages.
If len is not a power of two, the length is rounded up to the next
power of two. The returned PageRange struct stores the actual length
of the allocated page range.
§Returns
Ok(PageRange)if a range of pages was successfully allocatedErrif the requested range could not be satisfied by this allocator.
Source§fn dealloc_range(&self, range: PageRange<PAddr, S>) -> Result<(), AllocError>
fn dealloc_range(&self, range: PageRange<PAddr, S>) -> Result<(), AllocError>
Deallocate a range of pages.
§Returns
Ok(())if a range of pages was successfully deallocatedErrif the requested range could not be deallocated.