try_or_wrap_s 0.2.0

`?` or `try!` macro, with an additional wrapping of the error in something else
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented0 out of 0 items with examples
  • Size
  • Source code size: 39.15 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.05 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Ten0/rust-try_or_wrap_s
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Ten0

try_or_wrap

Crates.io License

This crate provides a macro similar to the old try! macro, or to the ?, except it wraps the error in something else.

This is useful if you want to use a ? for easily returning say, invalid input errors, but you can't do so because you have an additional Result level for handling internal errors of a different nature.

This macro allows you to do so:

fn foo(input: Input) -> Result<Result<FinalOutput, InvalidInputError>, DatabaseError> {
    let validated_input: ValidatedInput = try_or_wrap!(validate_input_with_database(input)?, Ok);
    Ok(Ok(do_stuff_with_validated_input(validated_input)?))
}

fn validate_input_with_database(input: Input) -> Result<Result<ValidatedInput, InvalidInputError>, DatabaseError>;