Skip to content

Commit a0f3b3b

Browse files
yoshuawuytsStjepan Glavina
authored and
Stjepan Glavina
committed
Remove unused macros (#610)
* replace async-macros with internals only Signed-off-by: Yoshua Wuyts <[email protected]> * clean up MaybeDone Signed-off-by: Yoshua Wuyts <[email protected]> * inline futures_core::ready Signed-off-by: Yoshua Wuyts <[email protected]> * remove big commented blob Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent f06ab9f commit a0f3b3b

File tree

9 files changed

+91
-9
lines changed

9 files changed

+91
-9
lines changed

Diff for: Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ docs = ["attributes", "unstable"]
3838
unstable = ["default", "broadcaster"]
3939
attributes = ["async-attributes"]
4040
std = [
41-
"async-macros",
4241
"crossbeam-utils",
4342
"futures-core",
4443
"futures-io",
@@ -51,7 +50,6 @@ std = [
5150

5251
[dependencies]
5352
async-attributes = { version = "1.1.1", optional = true }
54-
async-macros = { version = "2.0.0", optional = true }
5553
async-task = { version = "1.0.0", optional = true }
5654
broadcaster = { version = "0.2.6", optional = true, default-features = false, features = ["default-channels"] }
5755
crossbeam-channel = { version = "0.4.0", optional = true }

Diff for: src/future/future/join.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::pin::Pin;
22

3-
use async_macros::MaybeDone;
3+
use crate::future::MaybeDone;
44
use pin_project_lite::pin_project;
55

66
use crate::task::{Context, Poll};

Diff for: src/future/future/race.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::future::Future;
22
use std::pin::Pin;
33

4-
use async_macros::MaybeDone;
4+
use crate::future::MaybeDone;
55
use pin_project_lite::pin_project;
66

77
use crate::task::{Context, Poll};

Diff for: src/future/future/try_join.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::pin::Pin;
22

3-
use async_macros::MaybeDone;
3+
use crate::future::MaybeDone;
44
use pin_project_lite::pin_project;
55

66
use crate::task::{Context, Poll};

Diff for: src/future/future/try_race.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::pin::Pin;
22

3-
use async_macros::MaybeDone;
3+
use crate::future::MaybeDone;
44
use pin_project_lite::pin_project;
55

66
use crate::task::{Context, Poll};

Diff for: src/future/maybe_done.rs

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//! A type that wraps a future to keep track of its completion status.
2+
//!
3+
//! This implementation was taken from the original `macro_rules` `join/try_join`
4+
//! macros in the `futures-preview` crate.
5+
6+
use std::future::Future;
7+
use std::mem;
8+
use std::pin::Pin;
9+
use std::task::{Context, Poll};
10+
11+
use futures_core::ready;
12+
13+
/// A future that may have completed.
14+
#[derive(Debug)]
15+
pub(crate) enum MaybeDone<Fut: Future> {
16+
/// A not-yet-completed future
17+
Future(Fut),
18+
19+
/// The output of the completed future
20+
Done(Fut::Output),
21+
22+
/// The empty variant after the result of a [`MaybeDone`] has been
23+
/// taken using the [`take`](MaybeDone::take) method.
24+
Gone,
25+
}
26+
27+
impl<Fut: Future> MaybeDone<Fut> {
28+
/// Create a new instance of `MaybeDone`.
29+
pub(crate) fn new(future: Fut) -> MaybeDone<Fut> {
30+
Self::Future(future)
31+
}
32+
33+
/// Returns an [`Option`] containing a reference to the output of the future.
34+
/// The output of this method will be [`Some`] if and only if the inner
35+
/// future has been completed and [`take`](MaybeDone::take)
36+
/// has not yet been called.
37+
#[inline]
38+
pub(crate) fn output(self: Pin<&Self>) -> Option<&Fut::Output> {
39+
let this = self.get_ref();
40+
match this {
41+
MaybeDone::Done(res) => Some(res),
42+
_ => None,
43+
}
44+
}
45+
46+
/// Attempt to take the output of a `MaybeDone` without driving it
47+
/// towards completion.
48+
#[inline]
49+
pub(crate) fn take(self: Pin<&mut Self>) -> Option<Fut::Output> {
50+
unsafe {
51+
let this = self.get_unchecked_mut();
52+
match this {
53+
MaybeDone::Done(_) => {}
54+
MaybeDone::Future(_) | MaybeDone::Gone => return None,
55+
};
56+
if let MaybeDone::Done(output) = mem::replace(this, MaybeDone::Gone) {
57+
Some(output)
58+
} else {
59+
unreachable!()
60+
}
61+
}
62+
}
63+
}
64+
65+
impl<Fut: Future> Future for MaybeDone<Fut> {
66+
type Output = ();
67+
68+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
69+
let res = unsafe {
70+
match Pin::as_mut(&mut self).get_unchecked_mut() {
71+
MaybeDone::Future(a) => ready!(Pin::new_unchecked(a).poll(cx)),
72+
MaybeDone::Done(_) => return Poll::Ready(()),
73+
MaybeDone::Gone => panic!("MaybeDone polled after value taken"),
74+
}
75+
};
76+
self.set(MaybeDone::Done(res));
77+
Poll::Ready(())
78+
}
79+
}

Diff for: src/future/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,7 @@ cfg_default! {
6363

6464
cfg_unstable! {
6565
pub use into_future::IntoFuture;
66+
pub(crate) use maybe_done::MaybeDone;
6667
mod into_future;
68+
mod maybe_done;
6769
}

Diff for: src/task/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ cfg_std! {
121121
#[doc(inline)]
122122
pub use std::task::{Context, Poll, Waker};
123123

124-
#[doc(inline)]
125-
pub use async_macros::ready;
126-
124+
pub use ready::ready;
127125
pub use yield_now::yield_now;
126+
mod ready;
128127
mod yield_now;
129128
}
130129

Diff for: src/task/ready.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// Extracts the successful type of a `Poll<T>`.
2+
///
3+
/// This macro bakes in propagation of `Pending` signals by returning early.
4+
pub use futures_core::ready;

0 commit comments

Comments
 (0)