• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::future::Future;
2 use std::pin::Pin;
3 use std::task::{Context, Poll};
4 
5 /// Future for the [`ok`](ok()) function.
6 ///
7 /// `pub` in order to use the future as an associated type in a sealed trait.
8 #[derive(Debug)]
9 // Used as an associated type in a "sealed" trait.
10 #[allow(unreachable_pub)]
11 pub struct Ready<T>(Option<T>);
12 
13 impl<T> Unpin for Ready<T> {}
14 
15 impl<T> Future for Ready<T> {
16     type Output = T;
17 
18     #[inline]
poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T>19     fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
20         Poll::Ready(self.0.take().unwrap())
21     }
22 }
23 
24 /// Creates a future that is immediately ready with a success value.
ok<T, E>(t: T) -> Ready<Result<T, E>>25 pub(crate) fn ok<T, E>(t: T) -> Ready<Result<T, E>> {
26     Ready(Some(Ok(t)))
27 }
28