Expand description
#[derive(Future, Stream, Sink, AsyncRead, AsyncWrite, AsyncSeek, AsyncBufRead)] for enums.
§Examples
use futures_enum::*;
use std::future::Future;
#[derive(Future, Stream, Sink, AsyncRead, AsyncWrite, AsyncSeek, AsyncBufRead)]
enum Either<A, B> {
A(A),
B(B),
}
fn foo(x: i32) -> impl Future<Output = i32> {
if x < 0 { Either::A(async { 1 }) } else { Either::B(async move { x }) }
}
futures-enum works well even if the dependency contains only sub-crates such
as futures-core
, futures-io
, futures-sink
, etc.
See auto_enums crate for how to automate patterns like this.