Implemented Path::file_stem

yoshuawuyts-patch-1
Wouter Geraedts 5 years ago
parent a6e1abecfc
commit 28e936f6fe

@ -224,6 +224,32 @@ impl Path {
self.inner.file_name() self.inner.file_name()
} }
/// Extracts the stem (non-extension) portion of [`self.file_name`].
///
/// [`self.file_name`]: struct.Path.html#method.file_name
///
/// The stem is:
///
/// * [`None`], if there is no file name;
/// * The entire file name if there is no embedded `.`;
/// * The entire file name if the file name begins with `.` and has no other `.`s within;
/// * Otherwise, the portion of the file name before the final `.`
///
/// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
///
/// # Examples
///
/// ```
/// use async_std::path::Path;
///
/// let path = Path::new("foo.rs");
///
/// assert_eq!("foo", path.file_stem().unwrap());
/// ```
pub fn file_stem(&self) -> Option<&OsStr> {
self.inner.file_stem()
}
/// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or /// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
/// allocating. /// allocating.
/// ///

Loading…
Cancel
Save