std-method
Path::with_extension: derive another filename
Make an owned path with its final extension changed. It does not rename a file. Expected stdout (not executed): notes.md Common mistake: Expecting this method to perform a filesystem rename.
Formal Syntax & Structure
rust syntaxrust
path.with_extension(ext) -> PathBufWorking Example
Example Snippetrust
fn main() { use std::path::Path; let p = Path::new("notes.txt"); println!("{}", p.with_extension("md").file_name().unwrap().to_str().unwrap());}