#transpose #optional #option-option-t #option-transpose

optional_transpose

A small crate that adds .transpose() to Option<Option<T>>

1 unstable release

0.1.0 Apr 24, 2024

#5 in #transpose

MIT license

4KB

optional_transpose

A small crate that adds .transpose() to Option<Option<T>> It allows you to reversibly swap the inner and outer options in the pair, so that you can use ? on the inner option

Crates.io

Example:

use optional_transpose::OptionTranspose;

fn example() -> Option<i32> {
    let x: Option<Option<i32>> = Some(None);
    let y: Option<i32> = x.transpose()?; // Returns None, as the inner option is None
    Some(1)
}

assert_eq!(example(), None);

lib.rs:

optional_transpose

A small crate that adds .transpose() to Option<Option<T>> It allows you to reversibly swap the inner and outer options in the pair, so that you can use ? on the inner option

Example:

use optional_transpose::OptionTranspose;

fn example() -> Option<i32> {
    let x: Option<Option<i32>> = Some(None);
    let y: Option<i32> = x.transpose()?; // Returns None, as the inner option is None
    Some(1)
}

assert_eq!(example(), None);

No runtime deps