Skip to content

Instantly share code, notes, and snippets.

Created May 18, 2017 15:08
Show Gist options
  • Save anonymous/122a5b515c1f3e469a4ba25dca2a17fa to your computer and use it in GitHub Desktop.
Save anonymous/122a5b515c1f3e469a4ba25dca2a17fa to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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