Skip to main content

Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

A metric context.

Implementations§

Source§

impl Context

Source

pub fn from_static_name(name: &'static str) -> Self

Creates a new Context from the given static name.

Source

pub fn from_static_parts(name: &'static str, tags: &[&'static str]) -> Self

Creates a new Context from the given static name and given static tags.

Source

pub fn from_parts<S: Into<MetaString>>(name: S, tags: impl Into<TagSet>) -> Self

Creates a new Context from the given name and given tags.

Source

pub fn with_name<S: Into<MetaString>>(&self, name: S) -> Self

Clones this context, and uses the given name for the cloned context.

Source

pub fn with_tags(&self, tags: impl Into<TagSet>) -> Self

Clones this context, and uses the given tags for the cloned context.

The name and origin tags of this context are preserved.

Source

pub fn with_origin_tags(&self, origin_tags: impl Into<TagSet>) -> Self

Clones this context, and uses the given origin tags for the cloned context.

The name and instrumented tags of this context are preserved.

Source

pub fn with_tags_and_origin_tags( &self, tags: impl Into<TagSet>, origin_tags: impl Into<TagSet>, ) -> Self

Clones this context, replacing both instrumented tags and origin tags in a single allocation.

Preferred over two separate with_tags / with_origin_tags calls when both sets need to be replaced, as it halves the number of Arc allocations.

Source

pub fn name(&self) -> &MetaString

Returns the name of this context.

Source

pub fn tags(&self) -> &TagSet

Returns the instrumented tags of this context.

Source

pub fn origin_tags(&self) -> &TagSet

Returns the origin tags of this context.

Source

pub fn mutate_tags(&mut self, f: impl FnOnce(&mut TagSet))

Mutates the instrumented tags of this context via a closure.

Uses copy-on-write semantics: if this context shares its inner data with other clones, the inner data is cloned first so that mutations do not affect other holders. If this context is the sole owner, the mutation happens in place.

The context key is automatically recomputed after the closure returns.

Source

pub fn mutate_origin_tags(&mut self, f: impl FnOnce(&mut TagSet))

Mutates the origin tags of this context via a closure.

Uses copy-on-write semantics: if this context shares its inner data with other clones, the inner data is cloned first so that mutations do not affect other holders. If this context is the sole owner, the mutation happens in place.

The context key is automatically recomputed after the closure returns.

Source

pub fn with_tag_sets_mut(&mut self, f: impl FnOnce(&mut TagSet, &mut TagSet))

Mutates both instrumented tags and origin tags via a single closure.

Uses copy-on-write semantics: if this context shares its inner data with other clones, the inner data is cloned first so that mutations do not affect other holders. If this context is the sole owner, the mutation happens in place.

The context key is recomputed once after the closure returns.

Source

pub fn tags_mut_view<'a, 'b>( &'a mut self, state: &'b mut TagSetMutViewState, ) -> TagSetMutView<'a, 'b>

Creates a lazy copy-on-write mutable view over this context’s tag sets.

The returned view supports mutations (e.g. retain_tags) without immediately triggering an Arc clone. The actual clone, mutation, and context key recomputation only happen when TagSetMutView::finish is called, and only if changes were actually recorded.

state provides reusable scratch space for tracking pending changes. Holding a long-lived TagSetMutViewState across calls amortizes any vector allocations.

Source

pub fn size_of(&self) -> usize

Returns the size of this context in bytes.

A context’s size is the sum of the sizes of its fields and the size of the Context struct itself, and includes:

  • the context name
  • the context tags (both instrumented and origin)

Since origin tags can potentially be expensive to calculate, this method will cache the size of the origin tags when this method is first called.

Additionally, the value returned by this method does not compensate for externalities such as origin tags potentially being shared by multiple contexts, or whether or not tags are inlined, interned, or heap allocated. This means that the value returned is essentially the worst-case usage, and should be used as a rough estimate.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

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 Context

Source§

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

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

impl Display for Context

Source§

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

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

impl From<&'static str> for Context

Source§

fn from(name: &'static str) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<(&'static str, &'a [&'static str])> for Context

Source§

fn from((name, tags): (&'static str, &'a [&'static str])) -> Self

Converts to this type from the input type.
Source§

impl Hash for Context

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 PartialEq for Context

Source§

fn eq(&self, other: &Context) -> 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 Eq for Context

Source§

impl StructuralPartialEq for Context

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