Created
May 18, 2017 15:08
-
-
Save anonymous/122a5b515c1f3e469a4ba25dca2a17fa to your computer and use it in GitHub Desktop.
Rust code shared from the playground
This file contains 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
struct ATypeReturnedWithAnError; | |
struct IAmAnErrorType; | |
struct TheErrorIWant; | |
impl From<IAmAnErrorType> for TheErrorIWant { | |
fn from(_: IAmAnErrorType) -> Self { | |
unimplemented!() | |
} | |
} | |
fn function_easy_error() -> Result<(), IAmAnErrorType> { | |
unimplemented!() | |
} | |
fn function_less_easy_error() -> Result<(), (ATypeReturnedWithAnError, IAmAnErrorType)> { | |
unimplemented!() | |
} | |
fn main() { | |
let _: Result<_, TheErrorIWant> = function_easy_error().map_err(From::from); | |
let _: Result<_, TheErrorIWant> = function_less_easy_error().map_err(|(_, a)| a.into()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment