diff --git a/src/future/mod.rs b/src/future/mod.rs index 9b75533d3..d918ef083 100644 --- a/src/future/mod.rs +++ b/src/future/mod.rs @@ -48,17 +48,14 @@ cfg_alloc! { pub use future::Future; - pub(crate) mod future; -} - -cfg_std! { + pub use ready::ready; pub use pending::pending; pub use poll_fn::poll_fn; - pub use ready::ready; + pub(crate) mod future; + mod ready; mod pending; mod poll_fn; - mod ready; } cfg_default! { diff --git a/src/future/pending.rs b/src/future/pending.rs index 968972b51..f3a3379dc 100644 --- a/src/future/pending.rs +++ b/src/future/pending.rs @@ -1,6 +1,6 @@ -use std::future::Future; -use std::marker::PhantomData; -use std::pin::Pin; +use core::future::Future; +use core::marker::PhantomData; +use core::pin::Pin; use crate::task::{Context, Poll}; @@ -24,14 +24,17 @@ use crate::task::{Context, Poll}; /// # /// # }) /// ``` -pub async fn pending() -> T { - let fut = Pending { +pub fn pending() -> Pending { + Pending { _marker: PhantomData, - }; - fut.await + } } -struct Pending { +/// This future is constructed by the [`pending`] function. +/// +/// [`pending`]: fn.pending.html +#[derive(Debug)] +pub struct Pending { _marker: PhantomData, } diff --git a/src/future/poll_fn.rs b/src/future/poll_fn.rs index 194526400..1524d27c3 100644 --- a/src/future/poll_fn.rs +++ b/src/future/poll_fn.rs @@ -1,5 +1,5 @@ -use std::pin::Pin; -use std::future::Future; +use core::future::Future; +use core::pin::Pin; use crate::task::{Context, Poll}; @@ -23,15 +23,18 @@ use crate::task::{Context, Poll}; /// # /// # }) /// ``` -pub async fn poll_fn(f: F) -> T +pub fn poll_fn(f: F) -> PollFn where F: FnMut(&mut Context<'_>) -> Poll, { - let fut = PollFn { f }; - fut.await + PollFn { f } } -struct PollFn { +/// This future is constructed by the [`poll_fn`] function. +/// +/// [`poll_fn`]: fn.poll_fn.html +#[derive(Debug)] +pub struct PollFn { f: F, } diff --git a/src/future/ready.rs b/src/future/ready.rs index 65cba563d..0b7987362 100644 --- a/src/future/ready.rs +++ b/src/future/ready.rs @@ -1,3 +1,8 @@ +use core::future::Future; +use core::pin::Pin; + +use crate::task::{Context, Poll}; + /// Resolves to the provided value. /// /// This function is an async version of [`std::convert::identity`]. @@ -15,6 +20,22 @@ /// # /// # }) /// ``` -pub async fn ready(val: T) -> T { - val +pub fn ready(val: T) -> Ready { + Ready(Some(val)) +} + +/// This future is constructed by the [`ready`] function. +/// +/// [`ready`]: fn.ready.html +#[derive(Debug)] +pub struct Ready(Option); + +impl Unpin for Ready {} + +impl Future for Ready { + type Output = T; + + fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { + Poll::Ready(self.0.take().unwrap()) + } }