std-method

PathBuf::set_file_name: replace basename

Change the stored filename. Supply a single intended name; this does not move existing data. Expected stdout (not executed): final.txt Common mistake: Confusing a path edit with a file rename.

Formal Syntax & Structure

rust syntaxrust
path.set_file_name(name)

Working Example

Example Snippetrust
fn main() {    use std::path::PathBuf;    let mut p = PathBuf::from("draft.txt");    p.set_file_name("final.txt");    println!("{}", p.to_str().unwrap());}
Rust Reference