Skip to main content

tuwunel_core/utils/future/
mod.rs

1//! Additional combinators for futures and optional futures.
2//!
3//! The extensions compose Boolean, optional, and fallible outputs without
4//! awaiting them early. Comparison and selection helpers are included.
5
6mod bool_ext;
7mod ext_ext;
8mod option_ext;
9mod option_stream;
10mod ready_bool_ext;
11mod ready_eq_ext;
12mod try_ext_ext;
13
14pub use self::{
15	bool_ext::{BoolExt, and, and4, and5, and6, and7, or},
16	ext_ext::ExtExt,
17	option_ext::OptionFutureExt,
18	option_stream::OptionStream,
19	ready_bool_ext::ReadyBoolExt,
20	ready_eq_ext::ReadyEqExt,
21	try_ext_ext::TryExtExt,
22};
23
24/// Unwrap the value from a `Poll<Option<T>>`, early-returning from the
25/// enclosing function on `Ready(None)` or `Pending`.
26///
27/// Must be invoked inside a function returning `Poll<Option<_>>`, such as a
28/// `Stream::poll_next` impl; the `return` arms otherwise produce a type
29/// mismatch at the enclosing function's return.
30#[macro_export]
31macro_rules! ready_some {
32	($e:expr) => {
33		match $e {
34			| std::task::Poll::Ready(Some(v)) => v,
35			| std::task::Poll::Ready(None) => return std::task::Poll::Ready(None),
36			| std::task::Poll::Pending => return std::task::Poll::Pending,
37		}
38	};
39}