nostr: add Filter::tag#1383
Merged
Merged
Conversation
Add a Filter::tag(self, tag: Tag) convenience method that adds an already-constructed Tag to a Filter without manually decomposing it into a SingleLetterTag and value. Only single-letter tags can be indexed in a filter, so the method is a no-op when the tag has no single-letter representation or no value, deriving the value from the tag's serialized form rather than unwrapping. Closes nostrdevkit#1359
Closed
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1383 +/- ##
==========================================
+ Coverage 75.59% 75.64% +0.04%
==========================================
Files 199 199
Lines 32743 32770 +27
==========================================
+ Hits 24753 24789 +36
+ Misses 7990 7981 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
@mvanhorn Thank you for your contribution |
yukibtc
approved these changes
Jun 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a
Filter::tag(self, tag: Tag) -> Selfconvenience method (requested in #1359) so callers can add an already-constructedTagto aFilterdirectly, instead of manually decomposing it into aSingleLetterTagand a value with the verbosecustom_tag(tag.single_letter_tag().unwrap(), tag.content().unwrap())dance.The method:
tag.single_letter_tag(), since only single-letter tags can be indexed in a filter,Tag::to_vec, the element after the tag name),custom_tagso generic-tag storage stays in one place,selfunchanged when the tag has no single-letter representation or no value.This is additive and non-breaking.
Closes #1359
Notes to the reviewers
Following @TheAwiteb's guidance on the issue: not all tags fit in a filter, so the method handles the non-fitting case gracefully rather than unwrapping, and reads the value from the tag's serialized form rather than panicking. This gives callers (e.g. building a NIP-66 requirement filter) a clean builder method consistent with the existing
event/pubkey/hashtaghelpers.Inline unit tests in
crates/nostr/src/filter.rscover the happy path (a single-letterttag equals the matchingcustom_tag/hashtagcall), a multi-element single-letter tag indexing the value right after the tag name, chaining.tag()twice to accumulate values, and the two no-op cases (no single-letter representation, and no value).cargo test -p nostrpasses (245 + 8 tests).Checklist