New Error System is the library for rust, that makes the syntax more elegant for operating by errors.
Information about error:
Display ({})
example/examples/example.rs 16:0 //line, where impl_from_error!() is.
read file error example/examples/example.rs 51:13 //line where thr error has been occurred
Can not read file "no_file.rs" : No such file or directory (os error 2) //description of error
Debug ({:?})
example/examples/example.rs 18:0
CommonError::ReadFileError read_file_error:example/examples/example.rs 53:13
ReadFileError::ReadFileError io_error:Error { repr: Os { code: 2, message: "No such file or directory" } } file:"no_file.rs"
If you have some ideas, write them in Issues.
Cargo.toml
toml
nes = "*"
```rust //See examples/example.rs
defineerror!( ReadFileError,
IOError(ioerror:Box
defineerror!( CommonError,
ReadFileError(readfileerror:Box
implfromerror!(ReadFileError => CommonError);
fn process() -> result![CommonError] { let lines=read_file("file.rs")?;
for line in lines.iter() {
print!("L:{}",line);
}
ok!()
}
fn readfile(filename:String) -> result![Vec
let file=try!( std::fs::File::open(file_name.as_str()), ReadFileError::ReadFileError, file_name );
let mut buf_reader = std::io::BufReader::new(file);
let mut lines=Vec::new();
let mut line=String::with_capacity(80);
loop {
match try!( buf_reader.read_line(&mut line), ReadFileError::IOError ) {
0 => break,
_ => lines.push(line.clone()),
}
line.clear();
}
ok!(lines)
} ```
MIT