Closed
Description
What it does
Warns users that calling take
on an Option
created by as_mut
does not clear the original Option
.
It is useless to take
an Option
that is only holding a reference, one might as well pattern match on it directly.
Advantage
It makes it clearer that the original option is not modified.
Drawbacks
No response
Example
let mut option = Some("foo");
let maybe_foo = option.as_mut().take();
"Calling take
on an Option
with a reference does not clear the original Option
. Remove as_mut
or pattern-match on the option directly if you did not intend to clear it."
Could be written as:
let mut option = Some("foo");
let maybe_foo = option.take();
let mut option = Some("foo");
if let Some(a) = option.as_mut() {
// ...
}