Crates.io | futures-enum |
lib.rs | futures-enum |
version | 0.1.17 |
source | src |
created_at | 2019-02-02 07:48:59.012475 |
updated_at | 2021-01-05 16:49:44.259358 |
description | #[derive(Future, Stream, Sink, AsyncRead, AsyncWrite, AsyncSeek, AsyncBufRead)] for enums. |
homepage | |
repository | https://github.com/taiki-e/futures-enum |
max_upload_size | |
id | 112141 |
size | 44,784 |
#[derive(Future, Stream, Sink, AsyncRead, AsyncWrite, AsyncSeek, AsyncBufRead)] for enums.
Add this to your Cargo.toml
:
[dependencies]
futures-enum = "0.1.16"
futures = "0.3"
Compiler support: requires rustc 1.36+
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.
Future
- generated codeStream
- generated codeSink
- generated codeAsyncRead
- generated codeAsyncWrite
- generated codeAsyncSeek
- generated codeAsyncBufRead
- generated codeLicensed under either of Apache License, Version 2.0 or MIT license at your option.
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.