How can I effectively and idiomatically convert futures::FutureResult<std::boxed::Box<futures::Future<Error=futures::Canceled, Item=std::result::Result<X, errors::Error>>>, errors::Error>`
Not sure if I correctly understood your conversion requirement, but here's a shot:
extern crate futures;
use futures::future::{self, Future};
// I'm assuming errors::Error is something like this, in a nutshell
mod errors {
pub struct Error;
}
fn get_fut() -> future::FutureResult<
Box<
futures::Future<
Error = futures::Canceled,
Item = std::result::Result<String, errors::Error>,
>
+ Send, // <-- Note that we need to specify that this boxed Future is Send so we can rely on that later
>,
errors::Error,
> {
unimplemented!()
}
// An example where we want to take it as a generic type and monomorphize
fn call<F: Future<Error = errors::Error, Item = ()>>(_: F) {}
fn caller() {
call(get_fut().map(|_| ()));
}
// An example where we want to return it as a trait object
fn convert() -> Box<futures::Future<Error = errors::Error, Item = ()> + Send + 'static> {
let inner = get_fut();
Box::new(inner.map(|_| ()))
}
fn main() {}