pub struct TagSet { /* private fields */ }Expand description
A mutable set of tags, optionally backed by a SharedTagSet base.
TagSet supports efficient mutation through an overlay approach: it wraps an immutable SharedTagSet base with a
small set of additions and a bitset tracking which base tags have been removed. This avoids full materialization
when only a few tags need to change.
§Memory layout
When no mutations have been made, TagSet is compact (base pointer + None overlay). The mutation state
(additions and removals) is heap-allocated on demand only when insert_tag, remove_tags, or similar mutating
methods are called.
§Construction
A TagSet can be created from scratch (empty base, tags go into additions) or by wrapping an existing
SharedTagSet for mutation. When constructed from scratch, the usage pattern is the same as before: call
insert_tag in a loop, then into_shared to freeze.
§Conversion
When converting back to SharedTagSet via into_shared, if no mutations have been made,
the base is returned as-is with zero cost. Otherwise, the effective tags are materialized into a new
SharedTagSet.
Implementations§
Source§impl TagSet
impl TagSet
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new, empty TagSet with the given capacity for additions.
Sourcepub fn insert_tag<T>(&mut self, tag: T)
pub fn insert_tag<T>(&mut self, tag: T)
Inserts a tag into the set.
If the tag is already present in the set, this does nothing. Presence is checked by exact tag value (both name and value), not just by name — multiple tags with the same name but different values can coexist.
Removes all tags with the given name from the set.
Returns the removed tags, or None if no tags matched.
Sourcepub fn has_tag<T>(&self, tag: T) -> bool
pub fn has_tag<T>(&self, tag: T) -> bool
Returns true if the given tag is contained in the set.
This matches the complete tag, rather than just the name.
Sourcepub fn get_single_tag<T>(&self, tag_name: T) -> Option<&Tag>
pub fn get_single_tag<T>(&self, tag_name: T) -> Option<&Tag>
Gets a single tag, by name, from the set.
If multiple tags are present with the same name, the first tag with a matching name will be
returned. Additions are checked before the base. If no tag in the set matches, None is
returned.
Sourcepub fn retain<F>(&mut self, f: F)
pub fn retain<F>(&mut self, f: F)
Retains only the tags specified by the predicate.
In other words, remove all tags t for which f(&t) returns false.
Sourcepub fn merge_missing(&mut self, other: Self)
pub fn merge_missing(&mut self, other: Self)
Merges the tags from another set into this set.
If a tag from other is already present in this set, it will not be added.
Merges the tags from a shared set into this set.
If a tag from other is already present in this set, it will not be added.
Merges the tags from a shared set into this set.
This method does not attempt to avoid adding duplicate tags.
Consumes this TagSet and returns a shared, read-only version of it.
If no mutations have been made (no additions, no removals), the base SharedTagSet is
returned as-is with zero cost.
Sourcepub fn size_of(&self) -> usize
pub fn size_of(&self) -> usize
Returns the estimated size of the tag set, in bytes.
This includes the size of the base SharedTagSet, additions, and removal tracking. The value returned is a rough
estimate and does not compensate for inlined, interned, or heap-allocated tags.
Sourcepub fn is_modified(&self) -> bool
pub fn is_modified(&self) -> bool
Returns true if this TagSet has been modified from its base.
Trait Implementations§
Source§impl Extend<Tag> for TagSet
impl Extend<Tag> for TagSet
Source§fn extend<T: IntoIterator<Item = Tag>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = Tag>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§fn from(shared: SharedTagSet) -> Self
fn from(shared: SharedTagSet) -> Self
Source§impl FromIterator<Tag> for TagSet
impl FromIterator<Tag> for TagSet
Source§impl<'a> IntoIterator for &'a TagSet
impl<'a> IntoIterator for &'a TagSet
Source§impl IntoIterator for TagSet
impl IntoIterator for TagSet
impl Eq for TagSet
Auto Trait Implementations§
impl Freeze for TagSet
impl RefUnwindSafe for TagSet
impl Send for TagSet
impl Sync for TagSet
impl Unpin for TagSet
impl UnsafeUnpin for TagSet
impl UnwindSafe for TagSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> Track for T
impl<T> Track for T
§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
Tracked wrapper. Read more§fn in_current_allocation_group(self) -> Tracked<Self>
fn in_current_allocation_group(self) -> Tracked<Self>
Tracked wrapper. Read more