Skip to content

Commit 7ba1731

Browse files
committed
support no_std
1 parent 4b7aec5 commit 7ba1731

File tree

4 files changed

+246
-221
lines changed

4 files changed

+246
-221
lines changed

Cargo.toml

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,29 @@ homepage = "https://github.com/al8n/wg"
66
repository = "https://github.com/al8n/wg.git"
77
documentation = "https://docs.rs/wg/"
88
readme = "README.md"
9-
version = "0.7.4"
9+
version = "0.7.5"
1010
license = "MIT OR Apache-2.0"
1111
keywords = ["waitgroup", "async", "sync", "notify", "wake"]
1212
categories = ["asynchronous", "concurrency", "data-structures"]
1313
edition = "2021"
1414

1515
[features]
16-
default = []
17-
full = ["triomphe", "parking_lot"]
16+
default = ["std", "parking_lot", "triomphe"]
17+
std = ["triomphe?/default", "event-listener?/default", "futures-core?/default", "tokio?/rt"]
1818
triomphe = ["dep:triomphe"]
1919
parking_lot = ["dep:parking_lot"]
2020

2121
future = ["event-listener", "pin-project-lite"]
22-
2322
tokio = ["dep:tokio", "futures-core", "pin-project-lite"]
2423

2524
[dependencies]
2625
parking_lot = { version = "0.12", optional = true }
27-
triomphe = { version = "0.1", optional = true }
28-
event-listener = { version = "5", optional = true }
26+
triomphe = { version = "0.1", optional = true, default-features = false }
27+
event-listener = { version = "5", optional = true, default-features = false }
2928
pin-project-lite = { version = "0.2", optional = true }
3029

31-
tokio = { version = "1", default-features = false, optional = true, features = ["sync", "rt"] }
32-
futures-core = { version = "0.3", optional = true }
30+
tokio = { version = "1", optional = true, default-features = false, features = ["sync"] }
31+
futures-core = { version = "0.3", default-features = false, optional = true }
3332

3433
[dev-dependencies]
3534
tokio = { version = "1", features = ["full"] }

src/future.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
use super::*;
21
use event_listener::{Event, EventListener};
32

4-
use std::{
3+
use core::{
54
pin::Pin,
65
sync::atomic::{AtomicUsize, Ordering},
76
task::{Context, Poll},
87
};
98

9+
#[cfg(feature = "std")]
10+
use std::sync::Arc;
11+
12+
#[cfg(not(feature = "std"))]
13+
use alloc::sync::Arc;
14+
1015
#[derive(Debug)]
1116
struct AsyncInner {
1217
counter: AtomicUsize,
@@ -89,8 +94,8 @@ impl Clone for AsyncWaitGroup {
8994
}
9095
}
9196

92-
impl std::fmt::Debug for AsyncWaitGroup {
93-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97+
impl core::fmt::Debug for AsyncWaitGroup {
98+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
9499
f.debug_struct("AsyncWaitGroup")
95100
.field("counter", &self.inner.counter)
96101
.finish()
@@ -199,7 +204,7 @@ impl AsyncWaitGroup {
199204
WaitGroupFuture {
200205
inner: self,
201206
notified: self.inner.event.listen(),
202-
_pin: std::marker::PhantomPinned,
207+
_pin: core::marker::PhantomPinned,
203208
}
204209
}
205210

@@ -233,9 +238,11 @@ impl AsyncWaitGroup {
233238
/// wg.block_wait(spawner);
234239
/// # })
235240
/// ```
241+
#[cfg(feature = "std")]
242+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
236243
pub fn block_wait<S>(&self, spawner: S)
237244
where
238-
S: FnOnce(Pin<Box<dyn std::future::Future<Output = ()> + Send + 'static>>),
245+
S: FnOnce(Pin<Box<dyn core::future::Future<Output = ()> + Send + 'static>>),
239246
{
240247
let this = self.clone();
241248
let (tx, rx) = std::sync::mpsc::channel();
@@ -258,11 +265,11 @@ pin_project_lite::pin_project! {
258265
#[pin]
259266
notified: EventListener,
260267
#[pin]
261-
_pin: std::marker::PhantomPinned,
268+
_pin: core::marker::PhantomPinned,
262269
}
263270
}
264271

265-
impl<'a> std::future::Future for WaitGroupFuture<'a> {
272+
impl<'a> core::future::Future for WaitGroupFuture<'a> {
266273
type Output = ();
267274

268275
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {

0 commit comments

Comments
 (0)