error-tools 0.1.0
A catch-all error type with context chains, downcasting and bail/ensure macros
Install
cargo add error-tools --registry rupm
In Ruststudio: Packages, search for error-tools, Install.
Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-22.
Versions
- 0.1.0 2026-11-22
README
# error-tools
A catch-all error type with context chains, downcasting and bail/ensure macros
Add it with `rupm add error-tools` (or `cargo add error-tools --registry rupm`).
```rust
use error_tools::{bail, ensure, Context, Result};
fn read_port(text: &str) -> Result<u16> {
ensure!(!text.is_empty(), "port is empty");
let n = text.parse::<u16>().context("port is not a number")?;
if n == 0 {
bail!("port {} is reserved", n);
}
Ok(n)
}
let e = read_port("abc").unwrap_err();
assert_eq!(e.to_string(), "port is not a number");
assert!(format!("{e:#}").starts_with("port is not a number: "));
assert_eq!(read_port("8080").unwrap(), 8080);
```