When an option variable is known to be non-None
, its normally fine to write:
let var = option_var.unwrap();
In one case I ran into, this caused an error about moving out of borrowed context.
if let Some(var) = option_var { ... }
(Handy since it allows Some(ref mut var) = option_var
too).
This works, however in this case I don't want this to be an if
statement.
Writing let Some(var) = option_var;
fails with the error "pattern None
not covered".
To be clear this question isn't about borrowed context.
Can the let Some(var) = option;
syntax be used in a situation where it's known that it's not None
? Resolving the "Pattern None
not covered" warning? Or is this simply not supported outside an if
statement?