Crates.io | unwrap_all |
lib.rs | unwrap_all |
version | 0.2.0 |
source | src |
created_at | 2020-09-24 12:11:11.302387 |
updated_at | 2020-09-24 12:47:18.739642 |
description | Unpack multiple levels of `Result |
homepage | |
repository | https://gitlab.com/dns2utf8/unwrap_all |
max_upload_size | |
id | 292489 |
size | 8,249 |
With this crate I would like to explore the ergonomics of being able to unwrap multiple levels with one call.
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);
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);
}