-
Couldn't load subscription status.
- Fork 13.9k
Add std::path::Path::ancestors #48420
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
|
This hasn’t been assigned a reviewer, so assigning first person from T-libs, I can think of r? @BurntSushi |
src/libstd/path.rs
Outdated
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.
It might be useful to explicitly clarify here that the iterator returned will always yield at least one value.
|
I do agree with the utility of this function, and I've certainly had to write this iterator out by hand before. So I think this seems fine to me, but let's see if anyone has any objections before merging. cc @rust-lang/libs |
src/libstd/path.rs
Outdated
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.
This line raises two open questions for me:
- Is the feature name appropriate?
- What issue number can I use?
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 feature name seems OK to me, as long as it is distinct from any other feature name. :-)
I believe that if we decide to merge this, you need to create a tracking issue for stabilizing this feature, and that's the number that goes here.
I also think there is some docs where features are documented. But I don't know where it is.
|
Sounds like a great idea to me! We've actually got basically this method already in Cargo |
|
The name |
This seems like a weak justification for choosing |
|
I like these arguments. I will prepare a commit that changes the name to |
|
maybe |
|
I think, |
|
well, I think the name should be more or less generic, because it lists all paths, documentation should clarify the meaning though, another option |
The method does not list all paths at all. It lists all paths that are ancestors of Calling while all paths would (in my understanding of the term) be something like
In my opinion, something like @eav I really appreciate your ideas! But what is so wrong with |
|
Either |
|
@teiesti Could you squash this down to one commit? Then I think this should be good to go! |
Squashed commit of the following:
commit 1b5d55e26f667b1a25c83c5db0cbb072013a5122
Author: Tobias Stolzmann <tobias.stolzmann@gmail.com>
Date: Wed Feb 28 00:06:15 2018 +0100
Bugfix
commit 4265c2db0b0aaa66fdeace5d329665fd2d13903a
Author: Tobias Stolzmann <tobias.stolzmann@gmail.com>
Date: Tue Feb 27 22:59:12 2018 +0100
Rename std::path::Path::parents into std::path::Path::ancestors
commit 2548e4b14d377d20adad0f08304a0dd6f8e48e23
Author: Tobias Stolzmann <tobias.stolzmann@gmail.com>
Date: Tue Feb 27 12:50:37 2018 +0100
Add tracking issue
commit 3e2ce51a6eea0e39af05849f76dd2cefd5035e86
Author: Tobias Stolzmann <tobias.stolzmann@gmail.com>
Date: Mon Feb 26 15:05:15 2018 +0100
impl FusedIterator for Parents
commit a7e096420809740311e19d963d4aba6df77be2f9
Author: Tobias Stolzmann <tobias.stolzmann@gmail.com>
Date: Mon Feb 26 14:38:41 2018 +0100
Clarify that the iterator returned will yield at least one value
commit 796a36ea203cd197cc4c810eebd21c7e3433e6f1
Author: Tobias Stolzmann <tobias.stolzmann@gmail.com>
Date: Thu Feb 22 14:01:21 2018 +0100
Fix examples
commit e279383b21f11c97269cb355a5b2a0ecdb65bb0c
Author: Tobias Stolzmann <tobias.stolzmann@gmail.com>
Date: Thu Feb 22 04:47:24 2018 +0100
Add std::path::Path::parents
|
@BurntSushi Done. |
|
for me |
|
@bors r+ |
|
📌 Commit b9e9b4a has been approved by |
Tracking issue: #48581
This pull request adds a method called
parentsancestorstostd::path::Path.parentsancestorsis a generalized version ofparent. Whileparentreturns the path without its final component,parentsancestorsreturns an iterator that yields every ancestor. This includes the path itself, the parent, the grandparent and so on. This is done by repeatedly callingparent. In caseparentreturnsNone, the iterator returned byparentsancestorsdoes likewise.Why is such a method useful?
A method like
parentsancestorsis especially useful, if a task has to be done for the current directory and every directory up the tree. (Think of Cargo searching for the Cargo.toml!)Why does the iterator yield the original path instead of starting with the parent?
It is easier to skip the original path with
.skip(1)than it is to add the original path if necessary.Why is the method calledparentsinstead ofancestors?When sorted ,
parentscomes right afterparent. It is therefore grouped with its more specific counterpart within the documentation.Why is the method called
ancestorsinstead ofparents?ancestors.Ancestoryields the current path. It is more reasonable that the current path is a "null ancestor" than a "null parent".parentsmight be misleading.Two more notes: