2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-02-06 20:55:33 +00:00

feat: to no_std future::ready

This commit is contained in:
k-nasa 2020-02-04 18:01:50 +09:00
parent 94a6ff34c2
commit 3b9c7f0958

View file

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