std-method
Result::transpose
Move the Option layer outside. Ok(None) becomes None, Ok(Some(x)) becomes Some(Ok(x)), and Err(e) becomes Some(Err(e)). Expected stdout (not executed): Some(Err("invalid")) Common mistake: Treating Err as absent.
Formal Syntax & Structure
rust syntaxrust
Result<Option<T>, E>::transpose(self) -> Option<Result<T, E>>Working Example
Example Snippetrust
fn main() { let item: Result<Option<i32>, &str> = Err("invalid"); println!("{:?}", item.transpose());}