News for hackers. Stuff that matters.
Re:Rust: A Critical Retrospective by veber-alex on Thursday May 19, 2022 @12:07PM (#31436486)
Bar::Fail is not wrapped in a Result type, so you can't use '?' with it (on stable at least).

You can write it like this:

  let foo_result = match foo() {
    Ok(v) => v,
    Err(e) => return Bar::Fail(e)
  };
Re:Rust: A Critical Retrospective by loeg on Thursday May 19, 2022 @12:23PM (#31436668)
The result type is the return from Foo -- Bar::Fail does not need to wrap Result. Foo is Result<T, E> and map_err() would convert it to Result<T, Bar::Fail>. I think GP's `map_err()?` is the most straightforward way of writing this idea (and it's generally speaking how I would suggest writing Rust code).
Re:Rust: A Critical Retrospective by veber-alex on Thursday May 19, 2022 @12:27PM (#31436724)
GP's code will return Result<_, Bar>, the original code we are trying to fix just returns Bar.
Re:Rust: A Critical Retrospective by loeg on Thursday May 19, 2022 @12:38PM (#31436867)
If you are writing code to handle Results, it’s going to be a lot less painful to just return Result.