Struct snarkos_metrics::Key
source · [−]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
sourceimpl Key
impl Key
sourcepub fn from_parts<N, L>(name: N, labels: L) -> Key where
N: Into<KeyName>,
L: IntoLabels,
pub fn from_parts<N, L>(name: N, labels: L) -> Key where
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]) -> Key where
N: Into<KeyName>,
pub fn from_static_labels<N>(name: N, labels: &'static [Label]) -> Key where
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) -> 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, Global>)
pub fn into_parts(self) -> (KeyName, Vec<Label, Global>)
Consumes this Key
, returning the name parts and any labels.
Trait Implementations
sourceimpl Ord for Key
impl Ord for Key
sourceimpl PartialOrd<Key> for Key
impl PartialOrd<Key> for Key
sourcepub fn partial_cmp(&self, other: &Key) -> Option<Ordering>
pub fn partial_cmp(&self, other: &Key) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Key
Auto Trait Implementations
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcepub fn equivalent(&self, key: &K) -> bool
pub fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more