-
Notifications
You must be signed in to change notification settings - Fork 105
Path improvements
#546
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: main
Are you sure you want to change the base?
Path improvements
#546
Conversation
|
Draft for now: everything should work but I'd like to know which of these changes would be welcome, if any. Thanks for maintaining this by the way 🙂 |
|
One alternative I'm considering is a |
src/path/mod.rs
Outdated
| /// # Performance | ||
| /// | ||
| /// This operation is `O(n)`, similar to calling `.parts().count()` manually. | ||
| pub fn len(&self) -> usize { |
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 collides with the existing len provided by the deref to str
Edit: actually we don't implement deref but still callings this parts_count or something might be less ambiguous
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.
Would renaming empty and is_empty into root and is_root make sense?
44f4967 to
b49dd85
Compare
b49dd85 to
c6ccb69
Compare
|
Could I have one more CI run please? |
Done |
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 @Kinrany -- these changes look like a nice improvement to me
I think the code needs a few more tests -- doctests are fine (maybe even best) but otherwise this is ready to go in my mind
|
|
||
| /// Returns a copy of this [`Path`] with the last path segment removed | ||
| /// | ||
| /// Returns `None` if this path has zero segments. |
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 seems pretty similar to https://doc.rust-lang.org/std/path/struct.Path.html#method.parent
Should we call this method parent as well to follow existing convention?
| assert_eq!(Path::ROOT.parts().count(), Path::ROOT.parts_count()); | ||
|
|
||
| let path = path("foo/bar/baz"); | ||
| assert_eq!(path.parts().count(), path.parts_count()); |
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.
could you also please add an assertion that the count is 3?
|
|
||
| Self { raw } | ||
| impl<'a, I: Into<PathPart<'a>>> Extend<I> for Path { | ||
| fn extend<T: IntoIterator<Item = I>>(&mut self, iter: T) { |
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.
could you please add tests (perhaps doctests) using this feature explicitly to help others find it?
| if s.raw.is_empty() { | ||
| continue; | ||
| } | ||
| self.raw.push(DELIMITER_CHAR); |
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.
Can you add some tests showing how this works for:
- Empty iterators
- Iterator with a single element
- Iterator with multiple elements
- Extending an existing (non empty) Path? (it looks like maybe this will add an extra
/🤔 )
|
CI appears to show some regressions |
|
Thank you, will address! |
|
marking as draft while CI issues are resolved |
|
please mark it ready for review when it is ready for another look |
Which issue does this PR close?
Closes #545
Rationale for this change
fn prefix(&self)was the first thing I really wanted to have onPath, as opposed to copying from project to project.It also benefits from direct access to
raw. In userland we have to usepathsand collect, and omitting the last item is not trivial.What changes are included in this PR?
Implementations of everything listed with minimal docs, without tests.
Are there any user-facing changes?
Most of these changes are user-facing.
Internal changes:
impl FromIteratordelegates most of the logic toimpl ExpandPath::partsnow returns a custom iterator typeDELIMITER_CHARThere should be no breaking changes.