Skip to content

Commit

Permalink
feat: to no_std future::ready
Browse files Browse the repository at this point in the history
  • Loading branch information
k-nasa committed Feb 4, 2020
1 parent 28c0b31 commit 5a89f4c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/future/ready.rs
Original file line number Diff line number Diff line change
@@ -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`].
Expand All @@ -15,6 +20,22 @@
/// #
/// # })
/// ```
pub async fn ready<T>(val: T) -> T {
val
pub fn ready<T>(val: T) -> Ready<T> {
Ready(Some(val))
}

/// This future is constructed by the [`ready`] function.
///
/// [`ready`]: fn.ready.html
#[derive(Debug)]
pub struct Ready<T>(Option<T>);

impl<T> Unpin for Ready<T> {}

impl<T> Future for Ready<T> {
type Output = T;

fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> {
Poll::Ready(self.0.take().unwrap())
}
}

0 comments on commit 5a89f4c

Please sign in to comment.