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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion purl/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,17 @@ impl<T> GenericPurlBuilder<T> {
pub fn without_qualifier<S>(mut self, k: S) -> Self
where
S: AsRef<str>,
SmallString: From<S>,
{
self.parts.qualifiers.remove(k);
self
}

/// Unset all qualifiers.
pub fn without_qualifiers(mut self) -> Self {
self.parts.qualifiers.clear();
self
}

/// Set the subpath.
///
/// Passing `""` will unset the subpath.
Expand Down
20 changes: 19 additions & 1 deletion purl/src/qualifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<'a> IntoIterator for &'a mut Qualifiers {
/// A case-insensitive qualifier name.
///
/// Comparisons between this type and other types are case insensitive.
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[derive(Clone, Debug, Default, Eq, Hash, Ord)]
cd-work marked this conversation as resolved.
Show resolved Hide resolved
pub struct QualifierKey(SmallString);

impl<S> PartialEq<S> for QualifierKey
Expand Down Expand Up @@ -345,6 +345,24 @@ impl Deref for QualifierKey {
}
}

impl AsRef<str> for QualifierKey {
fn as_ref(&self) -> &str {
self.as_str()
}
}

impl From<QualifierKey> for SmallString {
fn from(value: QualifierKey) -> Self {
SmallString::from(value.0)
}
}

impl From<&QualifierKey> for SmallString {
fn from(value: &QualifierKey) -> Self {
SmallString::from(value.as_str())
}
}

impl QualifierKey {
/// Get a reference to the lower case string.
pub fn as_str(&self) -> &str {
Expand Down
Loading