This is how you convert from Option
to Result
and vice versa in Rust.
let err = anyhow!("some error");
let x = Some("foo");
assert_eq!(x.ok_or(err), Ok("foo"));
let x = Ok("foo");
assert_eq!(x.ok(), Some("foo"));
This is how you convert from Option
to Result
and vice versa in Rust.
let err = anyhow!("some error");
let x = Some("foo");
assert_eq!(x.ok_or(err), Ok("foo"));
let x = Ok("foo");
assert_eq!(x.ok(), Some("foo"));