1
Fork 0

Rollup merge of #102869 - azdavis:master, r=joshtriplett

Add basename and dirname aliases

Users might be used to the POSIX names of these functions. In fact, here's a [blog post][1] about this very thing.

[1]: https://boinkor.net/2019/07/basename-and-dirname-in-rust/
This commit is contained in:
Matthias Krüger 2022-10-11 18:59:49 +02:00 committed by GitHub
commit ccde95f489
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2158,6 +2158,7 @@ impl Path {
/// assert_eq!(grand_parent.parent(), None);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = "dirname")]
#[must_use]
pub fn parent(&self) -> Option<&Path> {
let mut comps = self.components();
@ -2225,6 +2226,7 @@ impl Path {
/// assert_eq!(None, Path::new("/").file_name());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = "basename")]
#[must_use]
pub fn file_name(&self) -> Option<&OsStr> {
self.components().next_back().and_then(|p| match p {