File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -173,6 +173,31 @@ impl Path {
173
173
fs:: metadata ( self ) . await . is_ok ( )
174
174
}
175
175
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
+
176
201
/// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
177
202
/// allocating.
178
203
///
You can’t perform that action at this time.
0 commit comments