Last active
December 27, 2021 14:22
-
-
Save jchia/5ba9852c67c96ca68dbe414f559e11df to your computer and use it in GitHub Desktop.
How to fix bar2() concisely? (bar1 is not concise)
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
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