optional_transpose 0.1.0

A small crate that adds `.transpose()` to `Option<Option<T>>`
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 3 items with examples
  • Size
  • Source code size: 3.39 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 146.58 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • rscarson/optional_transpose
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • rscarson

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);