diff options
Diffstat (limited to 'third_party/rust/tokio/src/future/ready.rs')
-rw-r--r-- | third_party/rust/tokio/src/future/ready.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/third_party/rust/tokio/src/future/ready.rs b/third_party/rust/tokio/src/future/ready.rs new file mode 100644 index 0000000000..d74f999e5d --- /dev/null +++ b/third_party/rust/tokio/src/future/ready.rs @@ -0,0 +1,27 @@ +use std::future::Future; +use std::pin::Pin; +use std::task::{Context, Poll}; + +/// Future for the [`ready`](ready()) function. +/// +/// `pub` in order to use the future as an associated type in a sealed trait. +#[derive(Debug)] +// Used as an associated type in a "sealed" trait. +#[allow(unreachable_pub)] +pub struct Ready<T>(Option<T>); + +impl<T> Unpin for Ready<T> {} + +impl<T> Future for Ready<T> { + type Output = T; + + #[inline] + fn poll(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<T> { + Poll::Ready(self.0.take().unwrap()) + } +} + +/// Creates a future that is immediately ready with a success value. +pub(crate) fn ok<T, E>(t: T) -> Ready<Result<T, E>> { + Ready(Some(Ok(t))) +} |