-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Add Path::has_trailing_sep
and related methods
#142506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
39ebcb7
to
1df54e4
Compare
This comment has been minimized.
This comment has been minimized.
9547ab7
to
c5f456e
Compare
This comment has been minimized.
This comment has been minimized.
c5f456e
to
f2e3481
Compare
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
Now that I know the workaround for the There are a few edge cases, namely removing the trailing separator from |
f2e3481
to
95dfe2b
Compare
This comment has been minimized.
This comment has been minimized.
95dfe2b
to
9b6cd12
Compare
@rustbot ready |
22c4da0
to
840b3a0
Compare
☔ The latest upstream changes (presumably #145334) made this pull request unmergeable. Please resolve the merge conflicts. |
/// assert_eq!(Path::new("dir/").trim_trailing_sep().as_os_str(), OsStr::new("dir")); | ||
/// assert_eq!(Path::new("dir").trim_trailing_sep().as_os_str(), OsStr::new("dir")); | ||
/// assert_eq!(Path::new("/").trim_trailing_sep().as_os_str(), OsStr::new("/")); | ||
/// assert_eq!(Path::new("//").trim_trailing_sep().as_os_str(), OsStr::new("//")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? I would have thought that since //
is the same as /
, this would trim //
to /
(but feel free to correct me).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea here is that removing any number of /
s would not affect the final path, and so, the path is left as-is. Essentially, any sequence of separators is treated as a single separator for the logic.
I could change it so that it returns /
here but it felt better to be conservative: the logic is that trailing separators are removed if doing so would result in the same path without a trailing separator. Since there will always be trailing separators here, it doesn't make a difference to remove any. If your goal is "cleaning up" the path, then normalize
and normalize_lexically
exist instead.
840b3a0
to
41c47ad
Compare
This comment has been minimized.
This comment has been minimized.
41c47ad
to
af3123d
Compare
Implements rust-lang/libs-team#335.
Tracking issue: #142503
Notable differences from ACP:
trim_trailing_sep
was added toPath
since it felt reasonable to ensure that the inverse operation was available.push_trailing_sep
andpop_trailing_sep
toPathBuf
in addition toset_trailing_sep
.This also updates some of the docs on various
Path
methods to use the term "trailing separator" instead of "trailing slash" for consistency.