diff --git a/Cargo.toml b/Cargo.toml index c1c29eb..69614af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,10 @@ page-alloc-64g = [] page-alloc-4g = [] page-alloc-256m = [] +axerrno = ["dep:axerrno"] + [dependencies] +axerrno = { version = "0.1", optional = true } cfg-if = "1.0" rlsf = { version = "0.2", optional = true } buddy_system_allocator = { version = "0.10", default-features = false, optional = true } diff --git a/src/lib.rs b/src/lib.rs index ab843be..1435e9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,9 @@ pub use tlsf::TlsfByteAllocator; use core::alloc::Layout; use core::ptr::NonNull; +#[cfg(feature = "axerrno")] +use axerrno::AxError; + /// The error type used for allocation. #[derive(Debug)] pub enum AllocError { @@ -47,6 +50,16 @@ pub enum AllocError { NotAllocated, } +#[cfg(feature = "axerrno")] +impl From for AxError { + fn from(value: AllocError) -> Self { + match value { + AllocError::NoMemory => AxError::NoMemory, + _ => AxError::InvalidInput, + } + } +} + /// A [`Result`] type with [`AllocError`] as the error type. pub type AllocResult = Result;