Created
April 14, 2018 09:28
-
-
Save mexus/c37243db0c9d3c8d5880b70c8be2151e to your computer and use it in GitHub Desktop.
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
#[macro_use] | |
extern crate failure; | |
use failure::Error; | |
#[derive(Fail, Debug)] | |
enum MyEnumError { | |
#[fail(display = "An error occurred.")] | |
Variant1, | |
#[fail(display = "A different error occurred.")] | |
Variant2(#[cause] ::std::io::Error), | |
} | |
fn err1() -> Result<(), Error> { | |
bail!(MyEnumError::Variant1) | |
} | |
impl From<::std::io::Error> for MyEnumError { | |
fn from(e: ::std::io::Error) -> Self { | |
MyEnumError::Variant2(e) | |
} | |
} | |
fn io_err() -> Result<(), MyEnumError> { | |
let _ = std::fs::File::open("/lolwut")?; | |
Ok(()) | |
} | |
fn io_err2() -> Result<(), Error> { | |
let _ = std::fs::File::open("/lolwut")?; | |
Ok(()) | |
} | |
fn main() -> Result<(), Error> { | |
let _ = err1()?; | |
let _ = io_err()?; | |
let _ = io_err2()?; | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment