// We want to show off that we can further manipulate the future before we need to run it, leaving
// it up to the end user to do with the results of the response as they please
We want to show off that we can further manipulate the future before we need to run it, leaving
it up to the end user to do with the results of the response as they please
We want to show off that we can further manipulate the future before we need to run it leaving it up to the end user to do with the results of the response as they please
pub fn work(future: impl Future<Item = Result<Response, Error>>) -> impl Future {
    future.and_then(|f| {
        // We're making a lot of assumptions here that we get a response back shaped like we
        // expect, but we know for certain that bar some kind of error it will be.
        let value = f.unwrap();
        let distance = value.result.get("distance").unwrap();
        let path = value
            .result
            .get("path")
            .unwrap()
            .as_array()
            .unwrap()
            .into_iter()
            .map(|e| e.as_str().unwrap())
            .collect::<Vec<&str>>();
        println!("Distance: {}\nPath: {:?}\n", distance, path);
        ok(())
    })
}
pub fn work ( future : impl Future < Item = Result < Response , Error > > ) -> impl Future { future . and_then ( | f | { // We're making a lot of assumptions here that we get a response back shaped like we // expect, but we know for certain that bar some kind of error it will be. let value = f . unwrap ( ) ; let distance = value . result . get ( " " ) . unwrap ( ) ; let path = value . result . get ( " " ) . unwrap ( ) . as_array ( ) . unwrap ( ) . into_iter ( ) . map ( | e | e . as_str ( ) . unwrap ( ) ) . collect :: < Vec < & str > > ( ) ; println ! ( " \n \n " distance path ) ; ok ( ( ) ) } ) }
We want to show off that we can further manipulate the future before we need to run it, leaving
it up to the end user to do with the results of the response as they please
We want to show off that we can further manipulate the future before we need to run it leaving it up to the end user to do with the results of the response as they please
future
impl Future<Item = Result<Response, Error>>