some-error 0.5.0

A library for creating and using anonymous sum types as errors in Rust
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented2 out of 2 items with examples
  • Size
  • Source code size: 9.71 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 291.79 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jam1garner

A library for allowing Anonymous Sum Types in the error of the returned result. The function this is attached to must return a type in the form of Result<T, E1 + E2 + ...>.

Example:

use std::io;
use some_error::*;

#[derive(Debug, Clone, Copy)]
struct NotZeroError(u32);

#[some_error]
fn my_func() -> Result<(), io::Error + NotZeroError>{
    let x = 3;
    if x != 0 {
        Err(NotZeroError(x))?;
    }

    Ok(())
}

fn main() {
    match my_func() {
        Ok(_) => {
            println!("Worked ok!");
        }
        Err(my_func::NotZeroError(NotZeroError(x))) => {
            println!("{} is not zero!!", x);
        }
        Err(my_func::io::Error(io_err)) => {
            println!("io error: {:?}", io_err);
        }
    }
}