File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2726,6 +2726,30 @@ impl Path {
2726
2726
new_path
2727
2727
}
2728
2728
2729
+ /// Creates an owned [`PathBuf`] like `self` but with an extra extension.
2730
+ ///
2731
+ /// See [`PathBuf::add_extension`] for more details.
2732
+ ///
2733
+ /// # Examples
2734
+ ///
2735
+ /// ```
2736
+ /// use std::path::{Path, PathBuf};
2737
+ ///
2738
+ /// let path = Path::new("foo.rs");
2739
+ /// assert_eq!(path.with_extra_extension("txt"), PathBuf::from("foo.rs.txt"));
2740
+ ///
2741
+ /// let path = Path::new("foo.tar.gz");
2742
+ /// assert_eq!(path.with_extra_extension(""), PathBuf::from("foo.tar.gz"));
2743
+ /// assert_eq!(path.with_extra_extension("xz"), PathBuf::from("foo.tar.gz.xz"));
2744
+ /// assert_eq!(path.with_extra_extension("").with_extra_extension("txt"), PathBuf::from("foo.tar.gz.txt"));
2745
+ /// ```
2746
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2747
+ pub fn with_extra_extension < S : AsRef < OsStr > > ( & self , extension : S ) -> PathBuf {
2748
+ let mut new_path = self . to_path_buf ( ) ;
2749
+ new_path. add_extension ( extension) ;
2750
+ new_path
2751
+ }
2752
+
2729
2753
/// Produces an iterator over the [`Component`]s of the path.
2730
2754
///
2731
2755
/// When parsing the path, there is a small amount of normalization:
You can’t perform that action at this time.
0 commit comments