unwrap_all 0.2.0

Unpack multiple levels of `Result<T, E>` and `Option<T>` at once
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented3 out of 3 items with examples
  • Size
  • Source code size: 8.58 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 261.74 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • dns2utf8/unwrap_all
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dns2utf8

unwrap_all

crates.io docs.rs

With this crate I would like to explore the ergonomics of being able to unwrap multiple levels with one call.

Example unwrap_all!(n_times, expression)

use unwrap_all::unwrap_all;

let nested: Option<Result<Option<Result<usize, ()>>, ()>> = Some(Ok(Some(Ok(42))));

let unpacked = unwrap_all!(4, nested);

assert_eq!(42, unpacked);

Example expect_all!(n_times, message, expression)

Running this function will give you a panic with the message 1 - must fail: 23, where the 1 tells you how many levels in the panic was caused.

use unwrap_all::expect_all;

fn must_fail() {
    let var = Some(Err::<usize, isize>(23));
    let _result: usize = expect_all!(2, "must fail", var);
}