1/// Helper function that might appear in Rust stable at some point
2/// (https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.transpose)
3pub fn transpose<T, E>(opt: Option<Result<T, E>>) -> Result<Option<T>, E> {
4 opt.map_or(Ok(None), |res| res.map(Some))
11 #[derive(Debug, PartialEq)]
14 type TestResult<T> = Result<T, TestError>;
18 let a: Option<TestResult<i32>> = Some(Ok(2));
19 assert_eq!(Ok(Some(2)), transpose(a));
21 let b: Option<TestResult<i32>> = Some(Err(TestError));
22 assert_eq!(Err(TestError), transpose(b));
24 let c: Option<TestResult<i32>> = None;
25 assert_eq!(Ok(None), transpose(c));
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list