Created
December 1, 2016 07:22
-
-
Save withoutboats/81f8185849a032de48aa2be126672d18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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