Skip to content
This repository was archived by the owner on Jan 4, 2026. It is now read-only.

Commit e70a7b2

Browse files
Switch from std to alloc (#9)
* Switch from std to alloc * Add back `std` feature flag, and fix small error in test configure gate * Fix no_std gating in lib.rs, and use `std` feature instead of `alloc` for docs.rs --------- Co-authored-by: Maximilien Cura <70043540+max-cura@users.noreply.github.com>
1 parent 8a1cd17 commit e70a7b2

6 files changed

Lines changed: 42 additions & 33 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ critical-section = [
4949
disable-cache-padding = [
5050
"maitake-sync?/no-cache-pad",
5151
]
52-
std = []
52+
alloc = []
53+
std = [
54+
"alloc"
55+
]
5356
maitake-sync-0_2 = [
5457
"dep:maitake-sync",
5558
]

src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
55
#![cfg_attr(not(any(test, feature = "std")), no_std)]
66

7+
#[cfg(feature = "alloc")]
8+
extern crate alloc;
9+
710
/// Type aliases for different generic configurations
811
///
912
pub mod nicknames;
@@ -26,7 +29,7 @@ pub mod export {
2629
pub use const_init::ConstInit;
2730
}
2831

29-
#[cfg(all(test, feature = "std"))]
32+
#[cfg(all(test, feature = "alloc"))]
3033
mod test {
3134
use core::{ops::Deref, time::Duration};
3235

@@ -39,7 +42,7 @@ mod test {
3942
},
4043
};
4144

42-
#[cfg(all(target_has_atomic = "ptr", feature = "std"))]
45+
#[cfg(all(target_has_atomic = "ptr", feature = "alloc"))]
4346
#[test]
4447
fn ux() {
4548
use crate::traits::{notifier::blocking::Blocking, storage::BoxedSlice};

src/nicknames.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
2222
#![allow(unused_imports)]
2323

24-
#[cfg(feature = "std")]
24+
#[cfg(feature = "alloc")]
2525
use crate::queue::ArcBBQueue;
2626
#[cfg(target_has_atomic = "ptr")]
2727
use crate::traits::coordination::cas::AtomicCoord;
2828
#[cfg(feature = "critical-section")]
2929
use crate::traits::coordination::cs::CsCoord;
30-
#[cfg(feature = "std")]
30+
#[cfg(feature = "alloc")]
3131
use crate::traits::storage::BoxedSlice;
3232
use crate::{
3333
queue::BBQueue,
@@ -51,49 +51,49 @@ pub type Churrasco<const N: usize> = BBQueue<Inline<N>, AtomicCoord, Blocking>;
5151
pub type Texas<const N: usize, A> = BBQueue<Inline<N>, AtomicCoord, A>;
5252

5353
/// Heap Buffer, Critical Section, Blocking, Borrowed
54-
#[cfg(all(feature = "std", feature = "critical-section"))]
54+
#[cfg(all(feature = "alloc", feature = "critical-section"))]
5555
pub type Braai = BBQueue<BoxedSlice, CsCoord, Blocking>;
5656

5757
/// Heap Buffer, Critical Section, Async, Borrowed
58-
#[cfg(all(feature = "std", feature = "critical-section"))]
58+
#[cfg(all(feature = "alloc", feature = "critical-section"))]
5959
pub type SiuMei<A> = BBQueue<BoxedSlice, CsCoord, A>;
6060

6161
/// Heap Buffer, Atomics, Blocking, Borrowed
62-
#[cfg(all(feature = "std", target_has_atomic = "ptr"))]
62+
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
6363
pub type YakiNiku = BBQueue<BoxedSlice, AtomicCoord, Blocking>;
6464

6565
/// Heap Buffer, Atomics, Async, Borrowed
66-
#[cfg(all(feature = "std", target_has_atomic = "ptr"))]
66+
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
6767
pub type Tandoori<A> = BBQueue<BoxedSlice, AtomicCoord, A>;
6868

6969
/// Inline Storage, Critical Section, Blocking, Arc
70-
#[cfg(all(feature = "std", feature = "critical-section"))]
70+
#[cfg(all(feature = "alloc", feature = "critical-section"))]
7171
pub type Asado<const N: usize> = ArcBBQueue<Inline<N>, CsCoord, Blocking>;
7272

7373
/// Inline Storage, Critical Section, Async, Arc
74-
#[cfg(all(feature = "std", feature = "critical-section"))]
74+
#[cfg(all(feature = "alloc", feature = "critical-section"))]
7575
pub type Carolina<const N: usize, A> = ArcBBQueue<Inline<N>, CsCoord, A>;
7676

7777
/// Inline Storage, Atomics, Blocking, Arc
78-
#[cfg(all(feature = "std", target_has_atomic = "ptr"))]
78+
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
7979
pub type Barbacoa<const N: usize> = ArcBBQueue<Inline<N>, AtomicCoord, Blocking>;
8080

8181
/// Inline Storage, Atomics, Async, Arc
82-
#[cfg(all(feature = "std", target_has_atomic = "ptr"))]
82+
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
8383
pub type KansasCity<const N: usize, A> = ArcBBQueue<Inline<N>, AtomicCoord, A>;
8484

8585
/// Heap Buffer, Critical Section, Blocking, Arc
86-
#[cfg(all(feature = "std", feature = "critical-section"))]
86+
#[cfg(all(feature = "alloc", feature = "critical-section"))]
8787
pub type Kebab = ArcBBQueue<BoxedSlice, CsCoord, Blocking>;
8888

8989
/// Heap Buffer, Critical Section, Async, Arc
90-
#[cfg(all(feature = "std", feature = "critical-section"))]
90+
#[cfg(all(feature = "alloc", feature = "critical-section"))]
9191
pub type Satay<A> = ArcBBQueue<BoxedSlice, CsCoord, A>;
9292

9393
/// Heap Buffer, Atomics, Blocking, Arc
94-
#[cfg(all(feature = "std", target_has_atomic = "ptr"))]
94+
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
9595
pub type GogiGui = ArcBBQueue<BoxedSlice, AtomicCoord, Blocking>;
9696

9797
/// Heap Buffer, Atomics, Async, Arc
98-
#[cfg(all(feature = "std", target_has_atomic = "ptr"))]
98+
#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
9999
pub type Lechon<A> = ArcBBQueue<BoxedSlice, AtomicCoord, A>;

src/queue.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
},
1313
};
1414

15-
#[cfg(feature = "std")]
15+
#[cfg(feature = "alloc")]
1616
use crate::traits::bbqhdl::BbqHandle;
1717

1818
/// A standard bbqueue
@@ -33,13 +33,13 @@ impl<S: Storage, C: Coord, N: Notifier> BBQueue<S, C, N> {
3333
}
3434

3535
/// A BBQueue wrapped in an Arc
36-
#[cfg(feature = "std")]
37-
pub struct ArcBBQueue<S, C, N>(pub(crate) std::sync::Arc<BBQueue<S, C, N>>);
36+
#[cfg(feature = "alloc")]
37+
pub struct ArcBBQueue<S, C, N>(pub(crate) alloc::sync::Arc<BBQueue<S, C, N>>);
3838

39-
#[cfg(feature = "std")]
39+
#[cfg(feature = "alloc")]
4040
impl<S: Storage, C: Coord, N: Notifier> ArcBBQueue<S, C, N> {
4141
pub fn new_with_storage(sto: S) -> Self {
42-
Self(std::sync::Arc::new(BBQueue::new_with_storage(sto)))
42+
Self(alloc::sync::Arc::new(BBQueue::new_with_storage(sto)))
4343
}
4444
}
4545

@@ -78,29 +78,29 @@ impl<S: Storage, C: Coord, N: Notifier> BBQueue<S, C, N> {
7878
}
7979
}
8080

81-
#[cfg(feature = "std")]
81+
#[cfg(feature = "alloc")]
8282
impl<S: Storage, C: Coord, N: Notifier> crate::queue::ArcBBQueue<S, C, N> {
83-
pub fn framed_producer(&self) -> FramedProducer<std::sync::Arc<BBQueue<S, C, N>>> {
83+
pub fn framed_producer(&self) -> FramedProducer<alloc::sync::Arc<BBQueue<S, C, N>>> {
8484
FramedProducer {
8585
bbq: self.0.bbq_ref(),
8686
pd: PhantomData,
8787
}
8888
}
8989

90-
pub fn framed_consumer(&self) -> FramedConsumer<std::sync::Arc<BBQueue<S, C, N>>> {
90+
pub fn framed_consumer(&self) -> FramedConsumer<alloc::sync::Arc<BBQueue<S, C, N>>> {
9191
FramedConsumer {
9292
bbq: self.0.bbq_ref(),
9393
pd: PhantomData,
9494
}
9595
}
9696

97-
pub fn stream_producer(&self) -> StreamProducer<std::sync::Arc<BBQueue<S, C, N>>> {
97+
pub fn stream_producer(&self) -> StreamProducer<alloc::sync::Arc<BBQueue<S, C, N>>> {
9898
StreamProducer {
9999
bbq: self.0.bbq_ref(),
100100
}
101101
}
102102

103-
pub fn stream_consumer(&self) -> StreamConsumer<std::sync::Arc<BBQueue<S, C, N>>> {
103+
pub fn stream_consumer(&self) -> StreamConsumer<alloc::sync::Arc<BBQueue<S, C, N>>> {
104104
StreamConsumer {
105105
bbq: self.0.bbq_ref(),
106106
}

src/traits/bbqhdl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ impl<S: Storage, C: Coord, N: Notifier> BbqHandle for &'_ BBQueue<S, C, N> {
8080
}
8181
}
8282

83-
#[cfg(feature = "std")]
84-
impl<S: Storage, C: Coord, N: Notifier> BbqHandle for std::sync::Arc<BBQueue<S, C, N>> {
83+
#[cfg(feature = "alloc")]
84+
impl<S: Storage, C: Coord, N: Notifier> BbqHandle for alloc::sync::Arc<BBQueue<S, C, N>> {
8585
type Target = Self;
8686
type Storage = S;
8787
type Coord = C;

src/traits/storage.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use const_init::ConstInit;
1414
use core::{cell::UnsafeCell, mem::MaybeUninit, ptr::NonNull};
1515

16+
#[cfg(feature = "alloc")]
17+
use alloc::{boxed::Box, vec::Vec};
18+
1619
/// Trait for providing access to the storage
1720
///
1821
/// Must always return the same ptr/len forever.
@@ -80,15 +83,15 @@ impl<const N: usize> Storage for &'_ Inline<N> {
8083
}
8184

8285
/// Boxed/heap-ful storage
83-
#[cfg(feature = "std")]
86+
#[cfg(feature = "alloc")]
8487
pub struct BoxedSlice {
8588
buf: Box<[UnsafeCell<MaybeUninit<u8>>]>,
8689
}
8790

88-
#[cfg(feature = "std")]
91+
#[cfg(feature = "alloc")]
8992
unsafe impl Sync for BoxedSlice {}
9093

91-
#[cfg(feature = "std")]
94+
#[cfg(feature = "alloc")]
9295
impl BoxedSlice {
9396
/// Create a new BoxedSlice with capacity `len`.
9497
pub fn new(len: usize) -> Self {
@@ -108,7 +111,7 @@ impl BoxedSlice {
108111
}
109112
}
110113

111-
#[cfg(feature = "std")]
114+
#[cfg(feature = "alloc")]
112115
impl Storage for BoxedSlice {
113116
fn ptr_len(&self) -> (NonNull<u8>, usize) {
114117
let len = self.buf.len();

0 commit comments

Comments
 (0)