| Crates.io | optional_transpose |
| lib.rs | optional_transpose |
| version | 0.1.0 |
| created_at | 2024-04-24 16:59:44.358692+00 |
| updated_at | 2024-04-24 16:59:44.358692+00 |
| description | A small crate that adds `.transpose()` to `Option |
| homepage | |
| repository | https://github.com/rscarson/optional_transpose |
| max_upload_size | |
| id | 1219312 |
| size | 3,702 |
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);