As of Rust 1.40, the standard library has Option::as_deref
to do this:
fn main() {
let opt: Option<String> = Some("some value".to_owned());
let value = opt.as_deref().unwrap_or("default string");
}
See also:
- How can I iterate on an Option<Vec<_>>?