2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-01-16 10:49:55 +00:00

Implemented Path::with_file_name

This commit is contained in:
Wouter Geraedts 2019-10-13 20:55:48 +02:00
parent 3c24b1891b
commit 409a10a8b5

View file

@ -728,6 +728,28 @@ impl Path {
pub fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {
self.inner.with_extension(extension).into()
}
/// Creates an owned [`PathBuf`] like `self` but with the given file name.
///
/// See [`PathBuf::set_file_name`] for more details.
///
/// [`PathBuf`]: struct.PathBuf.html
/// [`PathBuf::set_file_name`]: struct.PathBuf.html#method.set_file_name
///
/// # Examples
///
/// ```
/// use async_std::path::{Path, PathBuf};
///
/// let path = Path::new("/tmp/foo.txt");
/// assert_eq!(path.with_file_name("bar.txt"), PathBuf::from("/tmp/bar.txt"));
///
/// let path = Path::new("/tmp");
/// assert_eq!(path.with_file_name("var"), PathBuf::from("/var"));
/// ```
pub fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> PathBuf {
self.inner.with_file_name(file_name).into()
}
}
impl<'a> From<&'a std::path::Path> for &'a Path {