[][src]Crate futures_enum

#[derive(Future, Stream, Sink, AsyncRead, AsyncWrite, AsyncSeek, AsyncBufRead)] for enums.

Examples

use futures::future::{self, Future};
use futures_enum::*;

#[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(future::lazy(|_| 1))
    } else {
        Either::B(future::ready(x))
    }
}

See auto_enums for how to automate patterns like this.

futures-enum works well even if the dependency contains only sub-crates such as futures-core, futures-util, etc.

Supported traits

Derive Macros

AsyncBufRead
AsyncRead
AsyncSeek
AsyncWrite
Future
Sink
Stream