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/chain.rs | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 third_party/rust/futures-0.1.31/src/future/chain.rs (limited to 'third_party/rust/futures-0.1.31/src/future/chain.rs') diff --git a/third_party/rust/futures-0.1.31/src/future/chain.rs b/third_party/rust/futures-0.1.31/src/future/chain.rs new file mode 100644 index 0000000000..1bf5cd639c --- /dev/null +++ b/third_party/rust/futures-0.1.31/src/future/chain.rs @@ -0,0 +1,48 @@ +use core::mem; + +use {Future, Poll, Async}; + +#[derive(Debug)] +pub enum Chain where A: Future { + First(A, C), + Second(B), + Done, +} + +impl Chain + where A: Future, + B: Future, +{ + pub fn new(a: A, c: C) -> Chain { + Chain::First(a, c) + } + + pub fn poll(&mut self, f: F) -> Poll + where F: FnOnce(Result, C) + -> Result, B::Error>, + { + let a_result = match *self { + Chain::First(ref mut a, _) => { + match a.poll() { + Ok(Async::NotReady) => return Ok(Async::NotReady), + Ok(Async::Ready(t)) => Ok(t), + Err(e) => Err(e), + } + } + Chain::Second(ref mut b) => return b.poll(), + Chain::Done => panic!("cannot poll a chained future twice"), + }; + let data = match mem::replace(self, Chain::Done) { + Chain::First(_, c) => c, + _ => panic!(), + }; + match f(a_result, data)? { + Ok(e) => Ok(Async::Ready(e)), + Err(mut b) => { + let ret = b.poll(); + *self = Chain::Second(b); + ret + } + } + } +} -- cgit v1.2.3