diff --git a/src/path/path.rs b/src/path/path.rs index 2179c00d..21ab5e28 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -728,6 +728,28 @@ impl Path { pub fn with_extension>(&self, extension: S) -> PathBuf { self.inner.with_extension(extension).into() } + + /// Creates an owned [`PathBuf`] like `self` but with the given file name. + /// + /// See [`PathBuf::set_file_name`] for more details. + /// + /// [`PathBuf`]: struct.PathBuf.html + /// [`PathBuf::set_file_name`]: struct.PathBuf.html#method.set_file_name + /// + /// # Examples + /// + /// ``` + /// use async_std::path::{Path, PathBuf}; + /// + /// let path = Path::new("/tmp/foo.txt"); + /// assert_eq!(path.with_file_name("bar.txt"), PathBuf::from("/tmp/bar.txt")); + /// + /// let path = Path::new("/tmp"); + /// assert_eq!(path.with_file_name("var"), PathBuf::from("/var")); + /// ``` + pub fn with_file_name>(&self, file_name: S) -> PathBuf { + self.inner.with_file_name(file_name).into() + } } impl<'a> From<&'a std::path::Path> for &'a Path {