From a0b0c29ac837902ac649d4a258183410eec6ecb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9D=E5=80=89=E6=B0=B4=E5=B8=8C?= Date: Fri, 7 Nov 2025 15:17:41 +0800 Subject: [PATCH 1/2] feat: axerrno --- Cargo.toml | 1 + src/lib.rs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index c1c29eb..a8ab563 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ page-alloc-4g = [] page-alloc-256m = [] [dependencies] +axerrno = "0.1" 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..f74ad73 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,8 @@ pub use tlsf::TlsfByteAllocator; use core::alloc::Layout; use core::ptr::NonNull; +use axerrno::AxError; + /// The error type used for allocation. #[derive(Debug)] pub enum AllocError { @@ -47,6 +49,15 @@ pub enum AllocError { NotAllocated, } +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; From e9c72482feb20e27f0dcfda06cb63ec9ea65b4b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9D=E5=80=89=E6=B0=B4=E5=B8=8C?= Date: Sun, 9 Nov 2025 17:34:23 +0800 Subject: [PATCH 2/2] chore: add axerrno optional feature --- Cargo.toml | 4 +++- src/lib.rs | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a8ab563..69614af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,8 +26,10 @@ page-alloc-64g = [] page-alloc-4g = [] page-alloc-256m = [] +axerrno = ["dep:axerrno"] + [dependencies] -axerrno = "0.1" +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 f74ad73..1435e9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,6 +34,7 @@ pub use tlsf::TlsfByteAllocator; use core::alloc::Layout; use core::ptr::NonNull; +#[cfg(feature = "axerrno")] use axerrno::AxError; /// The error type used for allocation. @@ -49,6 +50,7 @@ pub enum AllocError { NotAllocated, } +#[cfg(feature = "axerrno")] impl From for AxError { fn from(value: AllocError) -> Self { match value {