Closed zakarumych closed 8 years ago
Unfortunately, this is not safe. If the modifying function panics, the &mut T will be left pointing to uninitialized memory, causing undefined behavior.
So there is no other way I guess.
@SCareAngel you might be interested in the take_mut
crate (crates.io/crates/take_mut) which provides a similar API.
@reem, it is interesting. While doing exactly the same it also terminate the program in case of sudden panic. So it can be used with caution. Thank you for link
Allow to modify values
&mut T
values with functions/closures that implementsFnOnce(T) -> T