File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -2743,12 +2743,27 @@ impl Path {
27432743 ///
27442744 /// let path = Path::new("foo.rs");
27452745 /// assert_eq!(path.with_extension("txt"), PathBuf::from("foo.txt"));
2746+ /// assert_eq!(path.with_extension(""), PathBuf::from("foo"));
2747+ /// ```
2748+ ///
2749+ /// Handling multiple extensions:
2750+ ///
2751+ /// ```
2752+ /// use std::path::{Path, PathBuf};
27462753 ///
27472754 /// let path = Path::new("foo.tar.gz");
2748- /// assert_eq!(path.with_extension(""), PathBuf::from("foo.tar"));
27492755 /// assert_eq!(path.with_extension("xz"), PathBuf::from("foo.tar.xz"));
27502756 /// assert_eq!(path.with_extension("").with_extension("txt"), PathBuf::from("foo.txt"));
27512757 /// ```
2758+ ///
2759+ /// Adding an extension where one did not exist:
2760+ ///
2761+ /// ```
2762+ /// use std::path::{Path, PathBuf};
2763+ ///
2764+ /// let path = Path::new("foo");
2765+ /// assert_eq!(path.with_extension("rs"), PathBuf::from("foo.rs"));
2766+ /// ```
27522767 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
27532768 pub fn with_extension < S : AsRef < OsStr > > ( & self , extension : S ) -> PathBuf {
27542769 self . _with_extension ( extension. as_ref ( ) )
You can’t perform that action at this time.
0 commit comments