Skip to content

Commit 3c24b18

Browse files
committed
Implemented Path::with_extension
1 parent a17b017 commit 3c24b18

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/path/path.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,25 @@ impl Path {
709709
pub fn to_string_lossy(&self) -> std::borrow::Cow<'_, str> {
710710
self.inner.to_string_lossy()
711711
}
712+
713+
/// Creates an owned [`PathBuf`] like `self` but with the given extension.
714+
///
715+
/// See [`PathBuf::set_extension`] for more details.
716+
///
717+
/// [`PathBuf`]: struct.PathBuf.html
718+
/// [`PathBuf::set_extension`]: struct.PathBuf.html#method.set_extension
719+
///
720+
/// # Examples
721+
///
722+
/// ```
723+
/// use async_std::path::{Path, PathBuf};
724+
///
725+
/// let path = Path::new("foo.rs");
726+
/// assert_eq!(path.with_extension("txt"), PathBuf::from("foo.txt"));
727+
/// ```
728+
pub fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {
729+
self.inner.with_extension(extension).into()
730+
}
712731
}
713732

714733
impl<'a> From<&'a std::path::Path> for &'a Path {

0 commit comments

Comments
 (0)