1use core::{
4 future::Future,
5 pin::Pin,
6 task::{Context, Poll},
7};
8
9#[derive(Debug, Clone)]
11#[must_use = "futures do nothing unless you `.await` or poll them"]
12pub struct Ready<T> {
13 val: Option<T>,
14}
15
16impl<T> Ready<T> {
17 #[inline]
19 pub fn into_inner(mut self) -> T {
20 self.val.take().unwrap()
21 }
22}
23
24impl<T> Unpin for Ready<T> {}
25
26impl<T> Future for Ready<T> {
27 type Output = T;
28
29 #[inline]
30 fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
31 let val = self.val.take().expect("Ready can not be polled twice.");
32 Poll::Ready(val)
33 }
34}
35
36#[allow(dead_code)]
38pub(crate) fn ready<T>(val: T) -> Ready<T> {
39 Ready { val: Some(val) }
40}
41
42#[allow(dead_code)]
44pub(crate) fn ok<T, E>(val: T) -> Ready<Result<T, E>> {
45 Ready { val: Some(Ok(val)) }
46}
47
48#[allow(dead_code)]
50pub(crate) fn err<T, E>(err: E) -> Ready<Result<T, E>> {
51 Ready {
52 val: Some(Err(err)),
53 }
54}