Skip to content

Commit a472413

Browse files
authored
feat: add conversion from AllocError to AxError (#6)
* feat: axerrno * chore: add axerrno optional feature
1 parent 88b065b commit a472413

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ page-alloc-64g = []
2626
page-alloc-4g = []
2727
page-alloc-256m = []
2828

29+
axerrno = ["dep:axerrno"]
30+
2931
[dependencies]
32+
axerrno = { version = "0.1", optional = true }
3033
cfg-if = "1.0"
3134
rlsf = { version = "0.2", optional = true }
3235
buddy_system_allocator = { version = "0.10", default-features = false, optional = true }

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub use tlsf::TlsfByteAllocator;
3434
use core::alloc::Layout;
3535
use core::ptr::NonNull;
3636

37+
#[cfg(feature = "axerrno")]
38+
use axerrno::AxError;
39+
3740
/// The error type used for allocation.
3841
#[derive(Debug)]
3942
pub enum AllocError {
@@ -47,6 +50,16 @@ pub enum AllocError {
4750
NotAllocated,
4851
}
4952

53+
#[cfg(feature = "axerrno")]
54+
impl From<AllocError> for AxError {
55+
fn from(value: AllocError) -> Self {
56+
match value {
57+
AllocError::NoMemory => AxError::NoMemory,
58+
_ => AxError::InvalidInput,
59+
}
60+
}
61+
}
62+
5063
/// A [`Result`] type with [`AllocError`] as the error type.
5164
pub type AllocResult<T = ()> = Result<T, AllocError>;
5265

0 commit comments

Comments
 (0)