From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../rust/futures-0.1.31/src/future/result.rs | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 third_party/rust/futures-0.1.31/src/future/result.rs (limited to 'third_party/rust/futures-0.1.31/src/future/result.rs') diff --git a/third_party/rust/futures-0.1.31/src/future/result.rs b/third_party/rust/futures-0.1.31/src/future/result.rs new file mode 100644 index 0000000000..5c44a63e1f --- /dev/null +++ b/third_party/rust/futures-0.1.31/src/future/result.rs @@ -0,0 +1,81 @@ +//! Definition of the `Result` (immediately finished) combinator + +use core::result; + +use {Future, Poll, Async}; + +/// A future representing a value that is immediately ready. +/// +/// Created by the `result` function. +#[derive(Debug, Clone)] +#[must_use = "futures do nothing unless polled"] +// TODO: rename this to `Result` on the next major version +pub struct FutureResult { + inner: Option>, +} + +/// Creates a new "leaf future" which will resolve with the given result. +/// +/// The returned future represents a computation which is finished immediately. +/// This can be useful with the `finished` and `failed` base future types to +/// convert an immediate value to a future to interoperate elsewhere. +/// +/// # Examples +/// +/// ``` +/// use futures::future::*; +/// +/// let future_of_1 = result::(Ok(1)); +/// let future_of_err_2 = result::(Err(2)); +/// ``` +pub fn result(r: result::Result) -> FutureResult { + FutureResult { inner: Some(r) } +} + +/// Creates a "leaf future" from an immediate value of a finished and +/// successful computation. +/// +/// The returned future is similar to `result` where it will immediately run a +/// scheduled callback with the provided value. +/// +/// # Examples +/// +/// ``` +/// use futures::future::*; +/// +/// let future_of_1 = ok::(1); +/// ``` +pub fn ok(t: T) -> FutureResult { + result(Ok(t)) +} + +/// Creates a "leaf future" from an immediate value of a failed computation. +/// +/// The returned future is similar to `result` where it will immediately run a +/// scheduled callback with the provided value. +/// +/// # Examples +/// +/// ``` +/// use futures::future::*; +/// +/// let future_of_err_1 = err::(1); +/// ``` +pub fn err(e: E) -> FutureResult { + result(Err(e)) +} + +impl Future for FutureResult { + type Item = T; + type Error = E; + + fn poll(&mut self) -> Poll { + self.inner.take().expect("cannot poll Result twice").map(Async::Ready) + } +} + +impl From> for FutureResult { + fn from(r: Result) -> Self { + result(r) + } +} -- cgit v1.2.3