Skip to main content

TagSet

Struct TagSet 

Source
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

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new, empty TagSet with the given capacity for additions.

Source

pub fn is_empty(&self) -> bool

Returns true if the tag set is empty.

Source

pub fn len(&self) -> usize

Returns the number of tags in the set.

Source

pub fn insert_tag<T>(&mut self, tag: T)
where T: Into<Tag>,

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.

Source

pub fn remove_tags<T>(&mut self, tag_name: T) -> Option<Vec<Tag>>
where T: AsRef<str>,

Removes all tags with the given name from the set.

Returns the removed tags, or None if no tags matched.

Source

pub fn has_tag<T>(&self, tag: T) -> bool
where T: AsRef<str>,

Returns true if the given tag is contained in the set.

This matches the complete tag, rather than just the name.

Source

pub fn get_single_tag<T>(&self, tag_name: T) -> Option<&Tag>
where T: AsRef<str>,

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.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&Tag) -> bool,

Retains only the tags specified by the predicate.

In other words, remove all tags t for which f(&t) returns false.

Source

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.

Source

pub fn merge_missing_shared(&mut self, other: &SharedTagSet)

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.

Source

pub fn merge_shared(&mut self, other: &SharedTagSet)

Merges the tags from a shared set into this set.

This method does not attempt to avoid adding duplicate tags.

Source

pub fn into_shared(self) -> SharedTagSet

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.

Source

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.

Source

pub fn is_modified(&self) -> bool

Returns true if this TagSet has been modified from its base.

Trait Implementations§

Source§

impl Clone for TagSet

Source§

fn clone(&self) -> TagSet

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TagSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TagSet

Source§

fn default() -> TagSet

Returns the “default value” for a type. Read more
Source§

impl Display for TagSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Extend<Tag> for TagSet

Source§

fn extend<T: IntoIterator<Item = Tag>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<SharedTagSet> for TagSet

Source§

fn from(shared: SharedTagSet) -> Self

Converts to this type from the input type.
Source§

impl From<Tag> for TagSet

Source§

fn from(tag: Tag) -> Self

Converts to this type from the input type.
Source§

impl From<TagSet> for SharedTagSet

Source§

fn from(tag_set: TagSet) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Tag> for TagSet

Source§

fn from_iter<I: IntoIterator<Item = Tag>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for TagSet

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> IntoIterator for &'a TagSet

Source§

type Item = &'a Tag

The type of the elements being iterated over.
Source§

type IntoIter = TagSetIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for TagSet

Source§

type Item = Tag

The type of the elements being iterated over.
Source§

type IntoIter = TagSetIntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq<TagSet> for SharedTagSet

Source§

fn eq(&self, other: &TagSet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for TagSet

Source§

fn eq(&self, other: &TagSet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for TagSet

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for TagSet

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> Stringable for T
where T: Display,

§

fn to_shared_string(&self) -> Cow<'static, str>

Converts the given value to a SharedString.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T> Track for T

§

fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>

Instruments this type by attaching the given allocation group token, returning a Tracked wrapper. Read more
§

fn in_current_allocation_group(self) -> Tracked<Self>

Instruments this type by attaching the current allocation group, returning a Tracked wrapper. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more