paperclip_core/
util.rs

1use std::{
2    future::Future,
3    marker::Unpin,
4    pin::Pin,
5    task::{Context, Poll},
6};
7
8/// Unstabilized [`Ready`](https://doc.rust-lang.org/nightly/std/future/struct.Ready.html) future.
9pub struct Ready<T>(Option<T>);
10
11impl<T> Unpin for Ready<T> {}
12
13impl<T> Future for Ready<T> {
14    type Output = T;
15
16    #[inline]
17    fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> {
18        Poll::Ready(self.0.take().expect("Ready polled after completion"))
19    }
20}
21
22/// Unstabilized [`ready`](https://doc.rust-lang.org/nightly/std/future/fn.ready.html) function.
23pub fn ready<T>(t: T) -> Ready<T> {
24    Ready(Some(t))
25}