Using temporary references inside of futures


#1

Assuming that the lifetime element of the signature of Bar::get cannot change (so you can use the reference inside the future it returns) is it possible to make this work?

extern crate futures;

use futures::Future;

pub trait Foo: 'static {
    fn parse(string: String) -> Box<Future<Item = Self, Error = ()>>;
}

pub trait Bar: 'static {                                                                                                                                                                       
    type Id: Foo;
    fn get<'a>(id: &'a Self::Id) -> Box<Future<Item = Self, Error = ()> + 'a>;
}

fn foo_bar<T: Bar>(string: String) -> Box<Future<Item = T, Error = ()>> {
    Box::new(<T::Id as Foo>::parse(string).and_then(|id| T::get(&id)))
}