Skip to content

Commit 28e936f

Browse files
committed
Implemented Path::file_stem
1 parent a6e1abe commit 28e936f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/path/path.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,32 @@ impl Path {
224224
self.inner.file_name()
225225
}
226226

227+
/// Extracts the stem (non-extension) portion of [`self.file_name`].
228+
///
229+
/// [`self.file_name`]: struct.Path.html#method.file_name
230+
///
231+
/// The stem is:
232+
///
233+
/// * [`None`], if there is no file name;
234+
/// * The entire file name if there is no embedded `.`;
235+
/// * The entire file name if the file name begins with `.` and has no other `.`s within;
236+
/// * Otherwise, the portion of the file name before the final `.`
237+
///
238+
/// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
239+
///
240+
/// # Examples
241+
///
242+
/// ```
243+
/// use async_std::path::Path;
244+
///
245+
/// let path = Path::new("foo.rs");
246+
///
247+
/// assert_eq!("foo", path.file_stem().unwrap());
248+
/// ```
249+
pub fn file_stem(&self) -> Option<&OsStr> {
250+
self.inner.file_stem()
251+
}
252+
227253
/// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
228254
/// allocating.
229255
///

0 commit comments

Comments
 (0)