Using a move function to modify a mut reference

Given type T that does not implement Default or Copy.

Given function f with the following signature:

fn f(x: T) -> T

Given mutable reference r of type &mut T.

Question: How do I replace the content of r with f(*r)?

https://crates.io/crates/take_mut

1 Like