Skip to content

Instantly share code, notes, and snippets.

@withoutboats
Created December 1, 2016 07:22
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/81f8185849a032de48aa2be126672d18 to your computer and use it in GitHub Desktop.
Save withoutboats/81f8185849a032de48aa2be126672d18 to your computer and use it in GitHub Desktop.
extern crate futures;
use std::str::FromStr;
use futures::{IntoFuture, Future};
fn foo<'a, T: Foo>(string: &'a str) -> Box<Future<Item = T, Error = ()> + 'a> {
Box::new(string.parse().into_future()
.or_else(|_| Err(()))
.and_then(|id| Foo::from_id(&id)))
}
pub trait Foo: 'static {
type Id: FromStr + 'static;
fn from_id<'a>(&'a Self::Id) -> Box<Future<Item = Self, Error = ()> + 'a>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment