#tuple #transpose #result #options

no-std tuple-transpose

Transpose tuple of results and options to result and option of tuple

1 unstable release

0.1.0 Nov 2, 2019

#2952 in Rust patterns

Download history 406/week @ 2024-03-13 462/week @ 2024-03-20 453/week @ 2024-03-27 479/week @ 2024-04-03 584/week @ 2024-04-10 481/week @ 2024-04-17 293/week @ 2024-04-24 319/week @ 2024-05-01 238/week @ 2024-05-08 379/week @ 2024-05-15 398/week @ 2024-05-22 426/week @ 2024-05-29 320/week @ 2024-06-05 269/week @ 2024-06-12 353/week @ 2024-06-19 319/week @ 2024-06-26

1,319 downloads per month
Used in memora

MIT license

6KB
95 lines

tuple-transpose

Transpose a tuple of results or options to result or option of tuple.

Examples

// Result
assert_eq!((Ok::<_, ()>(1u32), Ok(2.0f32)).transpose(), Ok((1u32, 2.0f32)));
assert_eq!((Ok(1u32), Err::<u64, _>(2.0f32)).transpose(), Err(2.0f32));
assert_eq!((Err::<i32, _>(1u32), Ok(2.0f32)).transpose(), Err(1u32));

// Option
assert_eq!((Some(1u32), Some(2.0f32)).transpose(), Some((1u32, 2.0f32)));
assert_eq!((Some(1u32), None::<f32>).transpose(), None::<(u32, f32)>);
assert_eq!((None::<u32>, Some(2.0f32)).transpose(), None::<(u32, f32)>);

No runtime deps