Hacker News new | ask | show | jobs
by yjh0502 2991 days ago
I used it frequently when mixing `Result` with `Future`. For example,

  fn do_something() -> Box<Future<Item=(), Error=Error>> {
    let val = match do_result() {
      Ok(x) => x,
      Err(e) => return Box::new(err(e.into())),
    };
    // do something with `val`
    unimplemented!();
  }
1 comments

If you want to cut down on lines, this is equivalent:

    let val = do_result().map_err(|e| Box::new(err(e.into())))?;