io_err

Crates.ioio_err
lib.rsio_err
version0.1.0
sourcesrc
created_at2022-05-23 19:02:42.728809
updated_at2022-05-23 19:02:42.728809
descriptionserializable `std::io::Error` with improved ergonomics
homepage
repositoryhttps://github.com/znx3p0/io_err
max_upload_size
id592008
size25,204
(znx3p0)

documentation

README

io_err

A serializable version of std::io::Error and std::io::Result with much better ergonomics.

fn test() -> Result<()> {
    let res: u32 = may_error()?;
    let another: Result<(), &'static str> = Err("error!");
    let map_another: Result<()> = another.map_err(err!(@other))?;
    err!((other, "error"))?; // == err!(("error"))?;
    Ok(())
}

fn return_error() -> Result<()> {
    err!(("unknown")) // == Err(err!("unknown"))
}

fn return_error_with_kind() -> Result<()> {
    err!((permission_denied, "unknown")) // == Err(err!(permission_denied, "unknown"))
}

fn simple_error() -> Result<()> {
    let err: Error = err!("unknown");
    Err(err)
}

fn simple_error_with_kind() -> Result<()> {
    let err: Error = err!(permission_denied, "unknown");
    Err(err)
}

fn errors() -> Result<()> {
    let err = "unknown";
    bail!("error {:?}", err); // == return err!(("error {:?}", err));
    Ok(())
}

fn permission_denied() -> Result<()> {
    let err = "denied >:(";
    bail!(permission_denied, "error {:?}", err);
    Ok(())
}
Commit count: 2

cargo fmt