Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3b9c7f0

Browse files
committed
feat: to no_std future::ready
1 parent 94a6ff3 commit 3b9c7f0

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

‎src/future/ready.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
use core::future::Future;
2+
use core::pin::Pin;
3+
4+
use crate::task::{Context, Poll};
5+
16
/// Resolves to the provided value.
27
///
38
/// This function is an async version of [`std::convert::identity`].
@@ -15,6 +20,22 @@
1520
/// #
1621
/// # })
1722
/// ```
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+
}
2041
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /