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

Improve ergonomics for qualifier keys #21

Merged
merged 3 commits into from
Nov 25, 2024
Merged

Conversation

matt-phylum
Copy link
Collaborator

Overview

I was writing some code to remove qualifiers from PURLs and found that you can't do purl.into_builder() and then remove all the qualifiers through builder methods without cloning the Purl or its qualifiers and then removing them one at a time, and even then the generics and type conversions for QualifierKey would get in the way of calling .without_qualifier or .with_qualifier using the keys of an existing Purl.

This PR

  • allows removing a qualifier using just any AsRef<str>, even one that isn't Into<SmallString>, because removing a qualifier never creates a string.
  • adds some impls for QualifierKey so that it the QualifierKey or &QualifierKey of an existing Purl can be used as a parameter to with_qualifier and without_qualifier.
  • adds a without_qualifiers that removes all qualifiers.

It might be nice in some cases to expose Qualifiers::retain somehow via PurlBuilder but I haven't done it in this PR. It is already possible to do that (and everything else added in this PR) by accessing the qualifiers directly:

let mut builder = purl.into_builder();
builder.parts.qualifiers.retain(|k, v| k == "checksum");
builder.build()

Checklist

  • Does this PR have an associated issue?
  • Have you ensured that you have met the expected acceptance criteria?
  • Have you created sufficient tests?

Issue

What issue(s) does this PR close. Use the closes #<issueNum> here.

purl/src/qualifiers.rs Show resolved Hide resolved
@matt-phylum matt-phylum merged commit d4a0282 into main Nov 25, 2024
6 checks passed
@matt-phylum matt-phylum deleted the matt/qualifier-key branch November 25, 2024 17:09
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.

2 participants