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) -> Key
pub fn from_parts<N, L>(name: N, labels: L) -> Key
Creates a Key from a name and set of labels.
Sourcepub fn from_static_labels<N>(name: N, labels: &'static [Label]) -> Key
pub fn from_static_labels<N>(name: N, labels: &'static [Label]) -> Key
Creates a Key from a non-static name and a static set of labels.
Sourcepub const fn from_static_name(name: &'static str) -> Key
pub const fn from_static_name(name: &'static str) -> Key
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],
) -> Key
pub const fn from_static_parts( name: &'static str, labels: &'static [Label], ) -> Key
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.
Trait Implementations§
Source§impl Ord for Key
impl Ord for Key
Source§impl PartialOrd for Key
impl PartialOrd for Key
impl Eq for Key
Auto Trait Implementations§
impl !Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
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> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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.