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§
source§impl Key
impl Key
sourcepub fn from_parts<N, L>(name: N, labels: L) -> Selfwhere
N: Into<KeyName>,
L: IntoLabels,
pub fn from_parts<N, L>(name: N, labels: L) -> Selfwhere N: Into<KeyName>, L: IntoLabels,
Creates a Key
from a name and set of labels.
sourcepub fn from_static_labels<N>(name: N, labels: &'static [Label]) -> Selfwhere
N: Into<KeyName>,
pub fn from_static_labels<N>(name: N, labels: &'static [Label]) -> Selfwhere N: Into<KeyName>,
Creates a Key
from a non-static name and a static set of labels.
sourcepub const fn from_static_name(name: &'static str) -> Self
pub const fn from_static_name(name: &'static str) -> Self
Creates a Key
from a static name.
This function is const
, so it can be used in a static context.
sourcepub const fn from_static_parts(
name: &'static str,
labels: &'static [Label]
) -> Self
pub const fn from_static_parts( name: &'static str, labels: &'static [Label] ) -> Self
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.
sourcepub fn into_parts(self) -> (KeyName, Vec<Label>)
pub fn into_parts(self) -> (KeyName, Vec<Label>)
Consumes this Key
, returning the name parts and any labels.
sourcepub fn with_extra_labels(&self, extra_labels: Vec<Label>) -> Self
pub fn with_extra_labels(&self, extra_labels: Vec<Label>) -> Self
Clones this Key
, and expands the existing set of labels.
Trait Implementations§
source§impl Ord for Key
impl Ord for Key
source§impl PartialEq for Key
impl PartialEq for Key
source§impl PartialOrd for Key
impl PartialOrd for Key
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more