A tiny crate for error handling. It is able to convert items of the
Error
trait into
their messages, allowing for easy propagation.
```rust use tiny_error::ErrorMessage;
use std::{ env, fs, path::PathBuf, };
fn main() -> Result<(), ErrorMessage> {
// Text when failed:
// Error: Invalid input
// Correct Usage: [crate_name] example/file/path.txt
let path = getpath()?;
// Text when failed:
// Error: No such file or directory (os error 2)
let file = fs::readto_string(path)?;
Ok(())
}
// Gets the first argument passed. If none or more were, returns an
// ErrorMessage
.
fn getpath() -> Result
arg
.map(|input| input.into())
.ok_or_else(|| ErrorMessage::new(
"Invalid input\n\
Correct Usage: `[crate_name] example/file/path.txt`"
))
} ```