pub struct Key { /* private fields */ }
Expand description
A metric identifier.
A key represents both the name and labels of a metric.
Safety
Clippy will report any usage of Key
as the key of a map/set as “mutable key type”, meaning
that it believes that there is interior mutability present which could lead to a key being
hashed different over time. That behavior could lead to unexpected behavior, as standard
maps/sets depend on keys having stable hashes over time, related to times when they must be
recomputed as the internal storage is resized and items are moved around.
In this case, the Hash
implementation of Key
does not depend on the fields which Clippy
considers mutable (the atomics) and so it is actually safe against differing hashes being
generated. We personally allow this Clippy lint in places where we store the key, such as
helper types in the metrics-util
crate, and you may need to do the same if you’re using it in
such a way as well.
Implementations
Creates a Key
from a name and set of labels.
pub fn from_static_labels<N>(name: N, labels: &'static [Label]) -> Self where
N: Into<KeyName>,
pub fn from_static_labels<N>(name: N, labels: &'static [Label]) -> Self where
N: Into<KeyName>,
Creates a Key
from a non-static name and a static set of labels.
Creates a Key
from a static name.
This function is const
, so it can be used in a static context.
Creates a Key
from a static name and static set of labels.
This function is const
, so it can be used in a static context.
Consumes this Key
, returning the name parts and any labels.
Clones this Key
, and expands the existing set of labels.
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Key
impl UnwindSafe for Key
Blanket Implementations
Mutably borrows from an owned value. Read more