I'm writing a custom_rename
function that receives a String
and an immutable reference to a PathBuf
:
fn custom_rename(new_name: String, old_path: &PathBuf) {
let mut new_path = PathBuf::from(&old_path);
new_path.pop();
new_path.push(new_name);
std::fs::rename(old_path, new_path).expect("error");
}
Does the PathBuf::from()
function clone the data of old_path
? According to The Rust Programming Language, Rustaceans try to avoid cloning.