Skip to content

Commit 4acd1d5

Browse files
committed
support stable Rust, introduce a new feature 'const_fn' on nightly
1 parent 411508a commit 4acd1d5

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
rust:
16+
- stable
1617
- nightly-2020-09-24
1718

1819
steps:

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ license = "MIT"
1313
[features]
1414
default = ["use_spin"]
1515
use_spin = ["spin"]
16+
const_fn = []
1617

1718
[dependencies.spin]
1819
version = "0.5"

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ unsafe {
2828

2929
You can also use `FrameAllocator` and `LockedHeapWithRescue`, see their documentation for usage.
3030

31+
## Features
32+
33+
- **`use_spin`** (default): Provide a `LockedHeap` type that implements the [`GlobalAlloc`] trait by using a spinlock.
34+
- **`const_fn`** (nightly only): Provide const fn version of `LockedHeapWithRescue::new`.
35+
36+
[`GlobalAlloc`]: https://doc.rust-lang.org/nightly/core/alloc/trait.GlobalAlloc.html
37+
3138
## License
3239

3340
Some code comes from phil-opp's linked-list-allocator.

src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(const_mut_refs, const_fn_fn_ptr_basics)]
1+
#![cfg_attr(feature = "const_fn", feature(const_mut_refs, const_fn_fn_ptr_basics))]
22
#![no_std]
33

44
#[cfg(test)]
@@ -287,12 +287,22 @@ pub struct LockedHeapWithRescue {
287287
#[cfg(feature = "use_spin")]
288288
impl LockedHeapWithRescue {
289289
/// Creates an empty heap
290+
#[cfg(feature = "const_fn")]
290291
pub const fn new(rescue: fn(&mut Heap)) -> LockedHeapWithRescue {
291292
LockedHeapWithRescue {
292293
inner: Mutex::new(Heap::new()),
293294
rescue,
294295
}
295296
}
297+
298+
/// Creates an empty heap
299+
#[cfg(not(feature = "const_fn"))]
300+
pub fn new(rescue: fn(&mut Heap)) -> LockedHeapWithRescue {
301+
LockedHeapWithRescue {
302+
inner: Mutex::new(Heap::new()),
303+
rescue,
304+
}
305+
}
296306
}
297307

298308
#[cfg(feature = "use_spin")]

0 commit comments

Comments
 (0)