-
Notifications
You must be signed in to change notification settings - Fork 341
/
Copy pathready.rs
41 lines (35 loc) · 868 Bytes
/
ready.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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`].
///
/// [`std::convert::identity`]: https://doc.rust-lang.org/std/convert/fn.identity.html
///
/// # Examples
///
/// ```
/// # async_std::task::block_on(async {
/// #
/// use async_std::future;
///
/// assert_eq!(future::ready(10).await, 10);
/// #
/// # })
/// ```
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())
}
}