Packages / rupm

rs-dev-error 0.1.0

A catch-all error type with context chains, downcasting and bail/ensure macros

Install

cargo add rs-dev-error --registry rupm

In Ruststudio: Packages, search for rs-dev-error, Install.

Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-23.

Versions

README

# rs-dev-error

A catch-all error type with context chains, downcasting and bail/ensure macros

Add it with `rupm add rs-dev-error` (or `cargo add rs-dev-error --registry rupm`).

```rust
use rs_dev_error::{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);
```