File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2702,6 +2702,30 @@ impl Path {
27022702 new_path
27032703 }
27042704
2705+ /// Creates an owned [`PathBuf`] like `self` but with an extra extension.
2706+ ///
2707+ /// See [`PathBuf::add_extension`] for more details.
2708+ ///
2709+ /// # Examples
2710+ ///
2711+ /// ```
2712+ /// use std::path::{Path, PathBuf};
2713+ ///
2714+ /// let path = Path::new("foo.rs");
2715+ /// assert_eq!(path.with_extra_extension("txt"), PathBuf::from("foo.rs.txt"));
2716+ ///
2717+ /// let path = Path::new("foo.tar.gz");
2718+ /// assert_eq!(path.with_extra_extension(""), PathBuf::from("foo.tar.gz"));
2719+ /// assert_eq!(path.with_extra_extension("xz"), PathBuf::from("foo.tar.gz.xz"));
2720+ /// assert_eq!(path.with_extra_extension("").with_extra_extension("txt"), PathBuf::from("foo.tar.gz.txt"));
2721+ /// ```
2722+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2723+ pub fn with_extra_extension < S : AsRef < OsStr > > ( & self , extension : S ) -> PathBuf {
2724+ let mut new_path = self . to_path_buf ( ) ;
2725+ new_path. add_extension ( extension) ;
2726+ new_path
2727+ }
2728+
27052729 /// Produces an iterator over the [`Component`]s of the path.
27062730 ///
27072731 /// When parsing the path, there is a small amount of normalization:
You can’t perform that action at this time.
0 commit comments