forked from mirror/async-std
Implemented Path::with_extension
This commit is contained in:
parent
a17b017e01
commit
3c24b1891b
1 changed files with 19 additions and 0 deletions
|
@ -709,6 +709,25 @@ impl Path {
|
|||
pub fn to_string_lossy(&self) -> std::borrow::Cow<'_, str> {
|
||||
self.inner.to_string_lossy()
|
||||
}
|
||||
|
||||
/// Creates an owned [`PathBuf`] like `self` but with the given extension.
|
||||
///
|
||||
/// See [`PathBuf::set_extension`] for more details.
|
||||
///
|
||||
/// [`PathBuf`]: struct.PathBuf.html
|
||||
/// [`PathBuf::set_extension`]: struct.PathBuf.html#method.set_extension
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use async_std::path::{Path, PathBuf};
|
||||
///
|
||||
/// let path = Path::new("foo.rs");
|
||||
/// assert_eq!(path.with_extension("txt"), PathBuf::from("foo.txt"));
|
||||
/// ```
|
||||
pub fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {
|
||||
self.inner.with_extension(extension).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a std::path::Path> for &'a Path {
|
||||
|
|
Loading…
Reference in a new issue