1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
extern crate futures;
use futures::future::Future;
pub type BoxFuture<T, E> = Box<Future<Item = T, Error = E> + Send>;
pub trait Boxable<T, E> {
fn to_boxed(self) -> BoxFuture<T, E>;
}
impl<F, T, E> Boxable<T, E> for F
where
F: Future<Item = T, Error = E> + Send + 'static,
{
fn to_boxed(self) -> BoxFuture<T, E>
where
Self: Sized,
{
Box::new(self)
}
}
#[macro_export]
macro_rules! try_future {
($x:expr) => {{
match $x {
Ok(value) => value,
Err(error) => {
use futures::future::err;
return err(error).to_boxed();
}
}
}};
}