Home 4. Option -> Result
Post
Cancel

4. Option -> Result

Convert Option to Result easily.

1
2
3
let o: Option<u32> = Some(200u32);
let r: Result<u32,()> = o.ok_or(());
assert_eq!(r, Ok(200u32));
This post is licensed under CC BY 4.0 by the author.