@@ -183,7 +183,7 @@ impl Path {
183
183
/// * Otherwise, the portion of the file name after the final `.`
184
184
///
185
185
/// [`self.file_name`]: struct.Path.html#method.file_name
186
- /// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html
186
+ /// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
187
187
///
188
188
/// # Examples
189
189
///
@@ -198,6 +198,32 @@ impl Path {
198
198
self . inner . extension ( )
199
199
}
200
200
201
+ /// Returns the final component of the `Path`, if there is one.
202
+ ///
203
+ /// If the path is a normal file, this is the file name. If it's the path of a directory, this
204
+ /// is the directory name.
205
+ ///
206
+ /// Returns [`None`] if the path terminates in `..`.
207
+ ///
208
+ /// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
209
+ ///
210
+ /// # Examples
211
+ ///
212
+ /// ```
213
+ /// use async_std::path::Path;
214
+ /// use std::ffi::OsStr;
215
+ ///
216
+ /// assert_eq!(Some(OsStr::new("bin")), Path::new("/usr/bin/").file_name());
217
+ /// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("tmp/foo.txt").file_name());
218
+ /// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.").file_name());
219
+ /// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.//").file_name());
220
+ /// assert_eq!(None, Path::new("foo.txt/..").file_name());
221
+ /// assert_eq!(None, Path::new("/").file_name());
222
+ /// ```
223
+ pub fn file_name ( & self ) -> Option < & OsStr > {
224
+ self . inner . file_name ( )
225
+ }
226
+
201
227
/// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
202
228
/// allocating.
203
229
///
0 commit comments