Skip to content

feat: Add key/value pair QoL improvements #711

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

Merged
merged 8 commits into from
Jan 12, 2024
Merged

Conversation

Techassi
Copy link
Member

@Techassi Techassi commented Jan 11, 2024

This PR adds two QoL improvements to the key/value pair API:

  • Add TryFrom<[(K, V); N]> impl for labels and annotations
  • Add Labels::parse_insert() and Annotations::parse_insert() functions. They take impl TryInto<_> as a parameter.

@Techassi Techassi self-assigned this Jan 11, 2024
@NickLarsenNZ
Copy link
Member

NickLarsenNZ commented Jan 11, 2024

Just so I understand it correctly, does that mean instead of:

    let labels: Labels =
        BTreeMap::from([("k", "v")])
            .try_into()
            .context(BuildLabelSnafu)?;

I would now do:

    let labels = Labels::try_from([("k", "v")])
            .context(BuildLabelSnafu)?;

Edit: I see the test that basically shows my second version

@Techassi
Copy link
Member Author

Techassi commented Jan 11, 2024

Yes! See

operator-rs/src/kvp/mod.rs

Lines 335 to 343 in 1c444b6

fn labels_from_array() {
let labels = Labels::try_from([
("stackable.tech/managed-by", "stackablectl"),
("stackable.tech/vendor", "Stackable"),
])
.unwrap();
assert_eq!(labels.len(), 2);
}
for a small example.

@NickLarsenNZ NickLarsenNZ self-requested a review January 11, 2024 18:26
NickLarsenNZ
NickLarsenNZ previously approved these changes Jan 11, 2024
Copy link
Member

@NickLarsenNZ NickLarsenNZ left a comment

Choose a reason for hiding this comment

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

Nice one! This is immediately useful (thought probably in the next round of operator maintenance)

@NickLarsenNZ NickLarsenNZ self-requested a review January 12, 2024 09:38
NickLarsenNZ
NickLarsenNZ previously approved these changes Jan 12, 2024
Copy link
Member

@NickLarsenNZ NickLarsenNZ left a comment

Choose a reason for hiding this comment

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

Nicely done 🚀

Copy link
Member

@NickLarsenNZ NickLarsenNZ left a comment

Choose a reason for hiding this comment

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

👍

@Techassi Techassi enabled auto-merge January 12, 2024 09:54
@Techassi Techassi added this pull request to the merge queue Jan 12, 2024
Merged via the queue into main with commit 91b156a Jan 12, 2024
@Techassi Techassi deleted the feat/kvps-qol-changes branch January 12, 2024 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants