2018-12-20 14:52:06 +01:00
|
|
|
use chainerror::*;
|
2018-12-21 13:50:08 +01:00
|
|
|
|
2018-12-20 10:08:54 +01:00
|
|
|
use std::error::Error;
|
2018-12-21 13:50:08 +01:00
|
|
|
use std::io;
|
2018-12-20 10:08:54 +01:00
|
|
|
use std::result::Result;
|
|
|
|
|
|
|
|
fn do_some_io() -> Result<(), Box<Error>> {
|
2018-12-21 13:50:08 +01:00
|
|
|
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
2018-12-20 10:08:54 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn func2() -> Result<(), Box<Error>> {
|
|
|
|
do_some_io().map_err(|e| cherr!(e, "func2 error"))?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn func1() -> Result<(), Box<Error>> {
|
|
|
|
func2().map_err(|e| cherr!(e, "func1 error"))?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<Error>> {
|
|
|
|
if let Err(e) = func1() {
|
|
|
|
eprintln!("{:?}", e);
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|