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 {
2743
2743
///
2744
2744
/// let path = Path::new("foo.rs");
2745
2745
/// 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};
2746
2753
///
2747
2754
/// let path = Path::new("foo.tar.gz");
2748
- /// assert_eq!(path.with_extension(""), PathBuf::from("foo.tar"));
2749
2755
/// assert_eq!(path.with_extension("xz"), PathBuf::from("foo.tar.xz"));
2750
2756
/// assert_eq!(path.with_extension("").with_extension("txt"), PathBuf::from("foo.txt"));
2751
2757
/// ```
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
+ /// ```
2752
2767
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2753
2768
pub fn with_extension < S : AsRef < OsStr > > ( & self , extension : S ) -> PathBuf {
2754
2769
self . _with_extension ( extension. as_ref ( ) )
You can’t perform that action at this time.
0 commit comments