File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -728,6 +728,28 @@ impl Path {
728
728
pub fn with_extension < S : AsRef < OsStr > > ( & self , extension : S ) -> PathBuf {
729
729
self . inner . with_extension ( extension) . into ( )
730
730
}
731
+
732
+ /// Creates an owned [`PathBuf`] like `self` but with the given file name.
733
+ ///
734
+ /// See [`PathBuf::set_file_name`] for more details.
735
+ ///
736
+ /// [`PathBuf`]: struct.PathBuf.html
737
+ /// [`PathBuf::set_file_name`]: struct.PathBuf.html#method.set_file_name
738
+ ///
739
+ /// # Examples
740
+ ///
741
+ /// ```
742
+ /// use async_std::path::{Path, PathBuf};
743
+ ///
744
+ /// let path = Path::new("/tmp/foo.txt");
745
+ /// assert_eq!(path.with_file_name("bar.txt"), PathBuf::from("/tmp/bar.txt"));
746
+ ///
747
+ /// let path = Path::new("/tmp");
748
+ /// assert_eq!(path.with_file_name("var"), PathBuf::from("/var"));
749
+ /// ```
750
+ pub fn with_file_name < S : AsRef < OsStr > > ( & self , file_name : S ) -> PathBuf {
751
+ self . inner . with_file_name ( file_name) . into ( )
752
+ }
731
753
}
732
754
733
755
impl < ' a > From < & ' a std:: path:: Path > for & ' a Path {
You can’t perform that action at this time.
0 commit comments