1use crate::future::Future;
2use crate::pin::Pin;
3use crate::task::{Context, Poll};
4
5#[stable(feature = "future_readiness_fns", since = "1.48.0")]
10#[derive(Debug, Clone)]
11#[must_use = "futures do nothing unless you `.await` or poll them"]
12pub struct Ready<T>(Option<T>);
13
14#[stable(feature = "future_readiness_fns", since = "1.48.0")]
15impl<T> Unpin for Ready<T> {}
16
17#[stable(feature = "future_readiness_fns", since = "1.48.0")]
18impl<T> Future for Ready<T> {
19 type Output = T;
20
21 #[inline]
22 fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
23 Poll::Ready(self.0.take().expect("`Ready` should not be polled after completion"))
24 }
25}
26
27impl<T> Ready<T> {
28 #[stable(feature = "ready_into_inner", since = "1.82.0")]
43 #[must_use]
44 #[inline]
45 pub fn into_inner(self) -> T {
46 self.0.expect("`into_inner()` should not be called on `Ready` after completion")
47 }
48}
49
50#[stable(feature = "future_readiness_fns", since = "1.48.0")]
67pub fn ready<T>(t: T) -> Ready<T> {
68 Ready(Some(t))
69}