mirror of
https://github.com/async-rs/async-std.git
synced 2025-04-08 17:36:43 +00:00
Implemented Path::file_name
This commit is contained in:
parent
a7eaae91ae
commit
a6e1abecfc
1 changed files with 27 additions and 1 deletions
|
@ -183,7 +183,7 @@ impl Path {
|
||||||
/// * Otherwise, the portion of the file name after the final `.`
|
/// * Otherwise, the portion of the file name after the final `.`
|
||||||
///
|
///
|
||||||
/// [`self.file_name`]: struct.Path.html#method.file_name
|
/// [`self.file_name`]: struct.Path.html#method.file_name
|
||||||
/// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html
|
/// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
@ -198,6 +198,32 @@ impl Path {
|
||||||
self.inner.extension()
|
self.inner.extension()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the final component of the `Path`, if there is one.
|
||||||
|
///
|
||||||
|
/// If the path is a normal file, this is the file name. If it's the path of a directory, this
|
||||||
|
/// is the directory name.
|
||||||
|
///
|
||||||
|
/// Returns [`None`] if the path terminates in `..`.
|
||||||
|
///
|
||||||
|
/// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use async_std::path::Path;
|
||||||
|
/// use std::ffi::OsStr;
|
||||||
|
///
|
||||||
|
/// assert_eq!(Some(OsStr::new("bin")), Path::new("/usr/bin/").file_name());
|
||||||
|
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("tmp/foo.txt").file_name());
|
||||||
|
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.").file_name());
|
||||||
|
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.//").file_name());
|
||||||
|
/// assert_eq!(None, Path::new("foo.txt/..").file_name());
|
||||||
|
/// assert_eq!(None, Path::new("/").file_name());
|
||||||
|
/// ```
|
||||||
|
pub fn file_name(&self) -> Option<&OsStr> {
|
||||||
|
self.inner.file_name()
|
||||||
|
}
|
||||||
|
|
||||||
/// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
|
/// Converts a [`Box<Path>`][`Box`] into a [`PathBuf`] without copying or
|
||||||
/// allocating.
|
/// allocating.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in a new issue