Skip to content

Instantly share code, notes, and snippets.

@withoutboats
Created December 1, 2016 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save withoutboats/efaf0a34fd439c736bbed99342f0344c to your computer and use it in GitHub Desktop.
Save withoutboats/efaf0a34fd439c736bbed99342f0344c to your computer and use it in GitHub Desktop.
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)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment