From 09308e93b8d2d74589754d62ba3531eb225c2f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Wed, 24 Sep 2025 09:20:37 +0800 Subject: [PATCH] feat: add no_std support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周睿 --- CHANGELOG.md | 3 +++ Cargo.toml | 6 +++++- src/allocation_engine/interval_tree.rs | 2 ++ src/id_allocator.rs | 2 +- src/lib.rs | 6 ++++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d3f837..8623fd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ## Upcoming version ### Added + +- Support for no_std environments. + ### Changed ### Fixed ### Removed diff --git a/Cargo.toml b/Cargo.toml index 97367bf..d363de7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,11 @@ keywords = ["resources", "allocation", "address", "virt"] license = "Apache-2.0 OR BSD-3-Clause" edition = "2018" +[features] +default = ["std"] +std = [] + [dependencies] libc = "0.2.39" -thiserror = "2.0" +thiserror = {version= "2.0", default-features = false} serde = { version = "1.0.137", optional = true, features = ["derive"] } diff --git a/src/allocation_engine/interval_tree.rs b/src/allocation_engine/interval_tree.rs index cbb56fa..d06c022 100644 --- a/src/allocation_engine/interval_tree.rs +++ b/src/allocation_engine/interval_tree.rs @@ -4,6 +4,8 @@ use std::cmp::{max, Ordering}; +use alloc::boxed::Box; + use crate::{AllocPolicy, Constraint, Error, RangeInclusive, Result}; /// Returns the first multiple of `alignment` that is lower or equal to the diff --git a/src/id_allocator.rs b/src/id_allocator.rs index 86037ff..5914dee 100644 --- a/src/id_allocator.rs +++ b/src/id_allocator.rs @@ -8,7 +8,7 @@ //! that can be abstracted to an integer. use crate::{Error, Result}; -use std::collections::BTreeSet; +use alloc::collections::BTreeSet; /// An unique ID allocator that allows management of IDs in a given interval. // Internal representation of IdAllocator. Contains the ends of the interval diff --git a/src/lib.rs b/src/lib.rs index e7eccd3..bbf2acb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,6 +74,12 @@ //! ``` #![deny(missing_docs)] +#![cfg_attr(not(feature = "std"), no_std)] + +extern crate alloc; + +#[cfg(not(feature = "std"))] +extern crate core as std; mod address_allocator; /// Allocation engine used by address allocator.