-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Implement Div and DivAssign for PathBuf #62989
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
Conversation
r? @dtolnay (rust_highfive has picked a reviewer for you, use r? to override) |
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.
Thanks for the PR! The implementation looks good.
This comment has been minimized.
This comment has been minimized.
@rfcbot fcp close I am not a fan of these. :( Does someone else from @rust-lang/libs want to make a case that we should have division operator on paths? let home = PathBuf::from("/home");
let user = Path::new("user");
assert_eq!(Path::new("/home/user/documents"), home / user / "documents"); |
Team member @dtolnay has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
FWIW, in trybuild I use a macro for this. let p = path!(project.dir / ".cargo" / "config"); I think that's more acceptable to me because the macro call puts it in the realm of domain-specific language rather than division. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Note that |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
I'll go ahead and close this. Thanks anyway, @1011X! I would still be interested in seeing something like path!(...) on crates.io. |
This change implements the
/
and/=
operators for concatenating paths to aPathBuf
, similar to how+
and+=
currently concatenate strings forString
.This would make it easier to build longer path values inline while improving readability. These operators have precedence in Python 3 and C++17, and in this implementation they can take either a
Path
,str
, orOsStr
.Examples:
I chose to submit a PR since that was the easier thing to do here, but if an RFC is preferred beforehand, I can do that too.