4 releases

Uses new Rust 2024

0.2.1 Feb 26, 2026
0.2.0 Oct 18, 2025
0.1.1 May 18, 2024
0.1.0 Apr 12, 2024

#714 in Rust patterns

Download history 76/week @ 2025-12-28 176/week @ 2026-01-04 128/week @ 2026-01-11 161/week @ 2026-01-18 70/week @ 2026-01-25 113/week @ 2026-02-01 132/week @ 2026-02-08 136/week @ 2026-02-15 94/week @ 2026-02-22 116/week @ 2026-03-01 128/week @ 2026-03-08 200/week @ 2026-03-15 155/week @ 2026-03-22 164/week @ 2026-03-29 307/week @ 2026-04-05 215/week @ 2026-04-12

860 downloads per month
Used in 2 crates

MIT license

6KB
102 lines

ERDP

Crates.io Version

ERDP is a small Rust crate with zero dependencies to help you display an error. If you use std::fmt::Display to display a std::error::Error like the following code:

use std::fs::File;
use std::path::{Path, PathBuf};
use thiserror::Error;

fn main() {
    let path = PathBuf::from("config.json");

    if let Err(e) = load_config(&path) {
        eprintln!("Failed to load {}: {}.", path.display(), e);
    }
}

fn load_config(path: &Path) -> Result<(), MyError> {
    let file = match File::open(path) {
        Ok(v) => v,
        Err(e) => return Err(MyError::OpenFileFailed(e)),
    };

    Ok(())
}

#[derive(Debug, Error)]
enum MyError {
    #[error("couldn't open the specified file")]
    OpenFileFailed(#[source] std::io::Error),
}

What you get is just a message from a top-level error:

Failed to load config.json: couldn't open the specified file.

With this crate you can use display method on the error value like:

use erdp::ErrorDisplay;

eprintln!("Failed to load {}: {}.", path.display(), e.display());

Then the output will change to something like:

Failed to load config.json: couldn't open the specified file -> No such file or directory.

Breaking changes in 0.2

  • ERDP now depend on alloc crate.
  • Rust minimum version now 1.85.

License

MIT

No runtime deps