We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 94a6ff3 commit 3b9c7f0Copy full SHA for 3b9c7f0
src/future/ready.rs
@@ -1,3 +1,8 @@
1
+use core::future::Future;
2
+use core::pin::Pin;
3
+
4
+use crate::task::{Context, Poll};
5
6
/// Resolves to the provided value.
7
///
8
/// This function is an async version of [`std::convert::identity`].
@@ -15,6 +20,22 @@
15
20
/// #
16
21
/// # })
17
22
/// ```
18
-pub async fn ready<T>(val: T) -> T {
19
- val
23
+pub fn ready<T>(val: T) -> Ready<T> {
24
+ Ready(Some(val))
25
+}
26
27
+/// This future is constructed by the [`ready`] function.
28
+///
29
+/// [`ready`]: fn.ready.html
30
+#[derive(Debug)]
31
+pub struct Ready<T>(Option<T>);
32
33
+impl<T> Unpin for Ready<T> {}
34
35
+impl<T> Future for Ready<T> {
36
+ type Output = T;
37
38
+ fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<T> {
39
+ Poll::Ready(self.0.take().unwrap())
40
+ }
41
}
0 commit comments