Skip to content

Instantly share code, notes, and snippets.

@jchia
Last active December 27, 2021 14: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 jchia/5ba9852c67c96ca68dbe414f559e11df to your computer and use it in GitHub Desktop.
Save jchia/5ba9852c67c96ca68dbe414f559e11df to your computer and use it in GitHub Desktop.
How to fix bar2() concisely? (bar1 is not concise)
fn foo() -> Result<(), std::io::Error> {
Ok(())
}
// Compiles, but verbose (using map_err).
fn bar1() -> Result<(), Box<dyn std::error::Error>> {
foo().map_err(|e| e.into())
}
// Does not compile.
fn bar2() -> Result<(), Box<dyn std::error::Error>> {
foo()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment