Skip to content
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

Tracking issue for std::path::Path::ancestors #48581

Closed
teiesti opened this Issue Feb 27, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@teiesti
Copy link
Contributor

teiesti commented Feb 27, 2018

Tracking issue for #48420, std::path::Path::ancestors and std::path::Ancestors.

Steps:

  • Implementation
  • Stabilization PR (#50894)

Unresolved questions:

  • What is a good name? ancestors? parents?

@teiesti teiesti changed the title Tracking issue for std::path::Path::parents Tracking issue for std::path::Path::ancestors Feb 27, 2018

@teiesti

This comment has been minimized.

Copy link
Contributor Author

teiesti commented Feb 28, 2018

Manishearth added a commit to Manishearth/rust that referenced this issue Feb 28, 2018

Rollup merge of rust-lang#48420 - teiesti:path_parents, r=BurntSushi
Add std::path::Path::ancestors

Tracking issue: rust-lang#48581

This pull request adds a method called ~`parents`~ `ancestors` to `std::path::Path`. ~`parents`~ `ancestors` is a generalized version of `parent`. While `parent` returns the path without its final component, ~`parents`~ `ancestors` returns an iterator that yields every ancestor. This includes the path itself, the parent, the grandparent and so on. This is done by repeatedly calling `parent`. In case `parent` returns `None`, the iterator returned by ~`parents`~ `ancestors` does likewise.

**Why is such a method useful?**
A method like ~`parents`~ `ancestors` is 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 called `parents` instead of `ancestors`?**
When sorted , `parents` comes right after `parent`. It is therefore grouped with its more specific counterpart within the documentation.~

**Why is the method called `ancestors` instead of `parents`?**
1. As @alexcrichton pointed out, Cargo has a similar method called `ancestors`.
2. As @sfackler pointed out, it might be weird that an iterator called `Ancestor` yields the current path. It is more reasonable that the current path is a "null ancestor" than a "null parent".
3. As @zackmdavis pointed out, the name `parents` might be misleading.

Two more notes:
1. Since this is my first contribution to the standard library, I am actually not sure if an RFC is required!
2. Since I am not a native speaker, someone should double-check my English!

bors added a commit that referenced this issue Jun 18, 2018

Auto merge of #50894 - teiesti:stabilize_path_ancestors, r=dtolnay
Stabilize std::path::Path::ancestors

Closes #48581

r? @BurntSushi

@bors bors closed this in #50894 Jun 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.