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()) + } }