| Crates.io | try_future |
| lib.rs | try_future |
| version | 0.1.3 |
| created_at | 2018-03-05 11:16:34.881161+00 |
| updated_at | 2018-08-14 10:02:20.214072+00 |
| description | Convenient short-hand for returning early from `futures`-based functions |
| homepage | |
| repository | https://github.com/srijs/rust-try-future |
| max_upload_size | |
| id | 53940 |
| size | 10,539 |
try_futureThis crate aims to provide a convenient short-hand for returning early
from futures-based functions.
The general pattern it supports is where before a function performs an asynchronous task, it does some work that might result in an early termination, for example:
impl Future<_>#[macro_use] extern crate try_future;
fn make_request<C: Connect>(target: &str, client: &Client<C>) ->
impl Future<Item=Response, Error=Error>
{
let uri = try_future!(target.parse::<Uri>());
client.get(uri).into()
}
Box<Future<_>>#[macro_use] extern crate try_future;
fn make_request<C: Connect>(target: &str, client: &Client<C>) ->
Box<Future<Item=Response, Error=Error>>
{
let uri = try_future_box!(target.parse::<Uri>());
Box::new(client.get(uri))
}