mem::replace
RS-W1113The std::mem
module provides the take()
method to acquire the
current value and replace it with the default value of the same type.
Prefer using this over mem::replace
with T::default()
.
let mut text = String::from("foo");
let replaced = std::mem::replace(&mut text, String::default());
let mut text = String::from("foo");
let taken = std::mem::take(&mut text);