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();
}
}
}};
}