Crates.io | mcoffin-tuple-ext |
lib.rs | mcoffin-tuple-ext |
version | 0.1.0 |
source | src |
created_at | 2020-11-17 16:27:07.336302 |
updated_at | 2020-11-17 16:27:07.336302 |
description | Simple option extension trait for dealing with tuples |
homepage | |
repository | |
max_upload_size | |
id | 313328 |
size | 6,783 |
Simple extension trait for Option
for working with tupleized results.
extern crate mcoffin_tuple_ext;
use mcoffin_tuple_ext::OptionExt;
fn main() {
let first = Some(1usize);
assert_eq!(first.and_tup(first), Some((1usize, 1usize)));
assert_eq!(first.and_tup(Some(2usize)), Some((1usize, 2usize)));
assert_eq!(first.and_tup::<usize>(None), None);
let v = first.and_then_tup(|_| Some("foo".to_string()));
assert!(v.is_some());
let (fst, snd) = v.unwrap();
assert_eq!(fst, 1);
assert_eq!(&snd, "foo");
}