Skip to content

Commit a7eaae9

Browse files
committed
Implemented Path::extension
1 parent 4070833 commit a7eaae9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/path/path.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,31 @@ impl Path {
173173
fs::metadata(self).await.is_ok()
174174
}
175175

176+
/// Extracts the extension of [`self.file_name`], if possible.
177+
///
178+
/// The extension is:
179+
///
180+
/// * [`None`], if there is no file name;
181+
/// * [`None`], if there is no embedded `.`;
182+
/// * [`None`], if the file name begins with `.` and has no other `.`s within;
183+
/// * Otherwise, the portion of the file name after the final `.`
184+
///
185+
/// [`self.file_name`]: struct.Path.html#method.file_name
186+
/// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html
187+
///
188+
/// # Examples
189+
///
190+
/// ```
191+
/// use async_std::path::Path;
192+
///
193+
/// let path = Path::new("foo.rs");
194+
///
195+
/// assert_eq!("rs", path.extension().unwrap());
196+
/// ```
197+
pub fn extension(&self) -> Option<&OsStr> {
198+
self.inner.extension()
199+
}
200+
176201
/// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
177202
/// allocating.
178203
///

0 commit comments

Comments
 (0)