From 28e936f6fec1d1a43df00c6452a36b1512052d28 Mon Sep 17 00:00:00 2001 From: Wouter Geraedts Date: Sun, 13 Oct 2019 19:05:18 +0200 Subject: [PATCH] Implemented Path::file_stem --- src/path/path.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/path/path.rs b/src/path/path.rs index 83af632..2c0f718 100644 --- a/src/path/path.rs +++ b/src/path/path.rs @@ -224,6 +224,32 @@ impl Path { 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`][`Box`] into a [`PathBuf`] without copying or /// allocating. ///