#futures #async #future #derive #enum

macro futures-enum

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

11 releases

✓ Uses Rust 2018 edition

new 0.1.10 Aug 14, 2019
0.1.9 Jul 4, 2019
0.1.8 Jun 16, 2019
0.1.7 May 15, 2019
0.1.4 Feb 21, 2019

#104 in Asynchronous

Download history 10/week @ 2019-04-29 10/week @ 2019-05-06 20/week @ 2019-05-13 33/week @ 2019-05-20 10/week @ 2019-05-27 8/week @ 2019-06-03 52/week @ 2019-06-10 31/week @ 2019-06-17 142/week @ 2019-06-24 45/week @ 2019-07-01 36/week @ 2019-07-08 1/week @ 2019-07-15 11/week @ 2019-07-22 15/week @ 2019-07-29 45/week @ 2019-08-05

143 downloads per month

Apache-2.0/MIT

17KB
249 lines

futures-enum

Build Status Crates.io Docs.rs License Minimum supported Rust version

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

Usage

Add this to your Cargo.toml:

[dependencies]
futures-enum = "0.1.10"
futures-preview = "0.3.0-alpha.17"

The current futures-enum requires Rust 1.36 or later.

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-io, etc.

Supported traits

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1MB
~25K SLoC