Skip to content

Conversation

@Kinrany
Copy link
Contributor

@Kinrany Kinrany commented Nov 11, 2025

Which issue does this PR close?

Closes #545

Rationale for this change

fn prefix(&self) was the first thing I really wanted to have on Path, as opposed to copying from project to project.

It also benefits from direct access to raw. In userland we have to use paths and collect, and omitting the last item is not trivial.

What changes are included in this PR?

Implementations of everything listed with minimal docs and tests.

Are there any user-facing changes?

Most of these changes are user-facing.

Internal changes:

  • impl FromIterator delegates most of the logic to impl Expand
  • Path::parts now returns a custom iterator type
  • Added DELIMITER_CHAR

There should be no breaking changes.

@Kinrany Kinrany mentioned this pull request Nov 11, 2025
@Kinrany
Copy link
Contributor Author

Kinrany commented Nov 11, 2025

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 🙂

@Kinrany
Copy link
Contributor Author

Kinrany commented Nov 11, 2025

One alternative I'm considering is a fn prefix that takes ownership and avoids cloning. The caller can always clone the original path first if necessary.

@Kinrany Kinrany marked this pull request as ready for review November 23, 2025 17:57
@Kinrany
Copy link
Contributor Author

Kinrany commented Nov 24, 2025

Could I have one more CI run please?

@alamb
Copy link
Contributor

alamb commented Nov 25, 2025

Could I have one more CI run please?

Done

Copy link
Contributor

@alamb alamb left a 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

src/path/mod.rs Outdated
assert_eq!(Path::ROOT.parts().count(), Path::ROOT.parts_count());

let path = path("foo/bar/baz");
assert_eq!(path.parts().count(), path.parts_count());
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, note that I haven't added any docs on Path directly. Since this is a standard trait, I expect people to find it by looking at the list of implemented traits 🤔

src/path/mod.rs Outdated
if s.raw.is_empty() {
continue;
}
self.raw.push(DELIMITER_CHAR);
Copy link
Contributor

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:

  1. Empty iterators
  2. Iterator with a single element
  3. Iterator with multiple elements
  4. Extending an existing (non empty) Path? (it looks like maybe this will add an extra / 🤔 )

@alamb alamb self-requested a review November 25, 2025 13:35
@alamb
Copy link
Contributor

alamb commented Nov 25, 2025

CI appears to show some regressions

@Kinrany
Copy link
Contributor Author

Kinrany commented Nov 26, 2025

Thank you, will address!

@alamb alamb marked this pull request as draft November 26, 2025 14:36
@alamb
Copy link
Contributor

alamb commented Nov 26, 2025

marking as draft while CI issues are resolved

@alamb
Copy link
Contributor

alamb commented Nov 26, 2025

please mark it ready for review when it is ready for another look

@alamb
Copy link
Contributor

alamb commented Dec 4, 2025

We are preparing the next release in a few days so if we want to include this one we need to get it ready to go

@Kinrany
Copy link
Contributor Author

Kinrany commented Dec 4, 2025

I was going to say I'll probably do it this weekend. But, oh look, I only meant to see how much I'll need to change and now it's done. Haha.

I added impl IntoIterator for &Path. I think that isn't controversial since it would be symmetrical to existing FromIterator?

@alamb
Copy link
Contributor

alamb commented Dec 4, 2025

Sounds reasonable (but I haven't thought about it deeply yet)

@Kinrany
Copy link
Contributor Author

Kinrany commented Dec 4, 2025

Is there a way to run the same checks that run in CI locally? Should I do anything other than cargo test && cargo clippy?

When tests run, a few items end up marked as unused. I assume that's fine. Or should I fix that in main in a separate PR first? Could be a toolchain update thing.

@Kinrany Kinrany marked this pull request as ready for review December 4, 2025 17:27
@alamb
Copy link
Contributor

alamb commented Dec 5, 2025

Is there a way to run the same checks that run in CI locally? Should I do anything other than cargo test && cargo clippy?

When tests run, a few items end up marked as unused. I assume that's fine. Or should I fix that in main in a separate PR first? Could be a toolchain update thing.

You can look at the output of the CI runs and see what commands it is running (they are all listed in various yml files in .github as well(

@Kinrany
Copy link
Contributor Author

Kinrany commented Dec 5, 2025

That should do it. All the new stuff has tests directly covering it now.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Kinrany -- this looks great to me. A very nice set of API improvements I think

@alamb alamb merged commit fa40170 into apache:main Dec 18, 2025
8 checks passed
@Kinrany
Copy link
Contributor Author

Kinrany commented Dec 18, 2025

Thank you!

@Kinrany Kinrany deleted the push-qnqozslwvlop branch December 18, 2025 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Path ergonomics

3 participants