Skip to content

Commit

Permalink
Const functions are stable since 1.61, so no need to feature guard them.
Browse files Browse the repository at this point in the history
  • Loading branch information
qwandor committed Jun 28, 2024
1 parent 7b49a0e commit 2f2635b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ jobs:
run: rustup default ${{ matrix.rust }}
- name: Build
run: cargo build --verbose
- name: Build without default features
run: cargo build --no-default-features --verbose
- name: Build with all features
run: cargo build --all-features --verbose
- name: Run tests
run: cargo test --verbose
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ homepage = "https://github.com/rcore-os/buddy_system_allocator"
repository = "https://github.com/rcore-os/buddy_system_allocator"
keywords = ["allocator", "no_std", "heap"]
version = "0.9.1"
authors = ["Jiajie Chen <[email protected]>", "Vinay Chandra Dommeti <[email protected]>", "Andrew Walbran <[email protected]>"]
authors = [
"Jiajie Chen <[email protected]>",
"Vinay Chandra Dommeti <[email protected]>",
"Andrew Walbran <[email protected]>",
]
edition = "2021"
license = "MIT"

[features]
default = ["use_spin"]
use_spin = ["spin"]
const_fn = []

[dependencies.spin]
version = "0.9.8"
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ You can also use `FrameAllocator` and `LockedHeapWithRescue`, see their document

## Features

- **`use_spin`** (default): Provide a `LockedHeap` type that implements the [`GlobalAlloc`] trait by using a spinlock.
- **`const_fn`** (nightly only): Provide const fn version of `LockedHeapWithRescue::new`.
- **`use_spin`** (default): Provide a `LockedHeap` type that implements the [`GlobalAlloc`] trait by
using a spinlock.

[`GlobalAlloc`]: https://doc.rust-lang.org/nightly/core/alloc/trait.GlobalAlloc.html

Expand All @@ -41,7 +41,7 @@ Some code comes from phil-opp's linked-list-allocator.

Licensed under MIT License. Thanks phill-opp's linked-list-allocator for inspirations and interface.

[crate-img]: https://img.shields.io/crates/v/buddy_system_allocator.svg
[crate]: https://crates.io/crates/buddy_system_allocator
[docs-img]: https://docs.rs/buddy_system_allocator/badge.svg
[docs]: https://docs.rs/buddy_system_allocator
[crate-img]: https://img.shields.io/crates/v/buddy_system_allocator.svg
[crate]: https://crates.io/crates/buddy_system_allocator
[docs-img]: https://docs.rs/buddy_system_allocator/badge.svg
[docs]: https://docs.rs/buddy_system_allocator
11 changes: 0 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg_attr(feature = "const_fn", feature(const_mut_refs, const_fn_fn_ptr_basics))]
#![no_std]

#[cfg(test)]
Expand Down Expand Up @@ -290,22 +289,12 @@ pub struct LockedHeapWithRescue<const ORDER: usize> {
#[cfg(feature = "use_spin")]
impl<const ORDER: usize> LockedHeapWithRescue<ORDER> {
/// Creates an empty heap
#[cfg(feature = "const_fn")]
pub const fn new(rescue: fn(&mut Heap<ORDER>, &Layout)) -> Self {
LockedHeapWithRescue {
inner: Mutex::new(Heap::<ORDER>::new()),
rescue,
}
}

/// Creates an empty heap
#[cfg(not(feature = "const_fn"))]
pub fn new(rescue: fn(&mut Heap<ORDER>, &Layout)) -> Self {
LockedHeapWithRescue {
inner: Mutex::new(Heap::<ORDER>::new()),
rescue,
}
}
}

#[cfg(feature = "use_spin")]
Expand Down

0 comments on commit 2f2635b

Please sign in to comment.