I don't know if I am missing something, but I just stumbled upon a minor papercut in std::option::Option
.
I have two variables opt: &'a mut Option<T>
and value: T
. I want to unconditionally assign Some(value)
to *opt
and then return a mutable reference to the value inside opt (so the return type is &'a mut T
).
This should be possible without an unwrap, but I don't know how. Option::get_or_insert
only inserts when the old value is None
.
If there is no such method, would it be worthwhile to create an issue/PR/RFC against the standard library? There are already many convenience methods fixing similar papercuts.