match_err

Crates.iomatch_err
lib.rsmatch_err
version0.1.9
sourcesrc
created_at2024-08-01 20:54:10.58098
updated_at2024-08-06 06:30:40.993751
descriptionMacro for matching enum-like errors
homepagehttps://github.com/blkmlk/match_err
repositoryhttps://github.com/blkmlk/match_err
max_upload_size
id1322520
size9,424
Islam Bekbuzarov (blkmlk)

documentation

https://docs.rs/match_err

README

match_err

Macro for quick matching errors against enum-like error types

Helps to avoid writing long and tedious structures like:

if let Err(e) = err {
    if let Some(e) = e.downcast_ref::<Error>() {
        match e {
            ...
        }
    }
}

Examples

use match_err::*;

#[derive(thiserror::Error, Debug)]
enum Error {
    #[error("not found")]
    NotFound,
    #[error("custom: {0}")]
    Custom(String),
}

let err: Result<(), _> = Err(anyhow!(Error::NotFound));

match_if_err!(err, Error, {
    NotFound => println!("not found"),
    Custom(msg) => println!("custom message: {}", msg),
    _ => println!("unknown")
})
Commit count: 0

cargo fmt