#tuple #transpose #options #result

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

#6 in #transpose


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