1use crate::MetricKind;
2use metrics::Key;
3
4#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
6pub struct CompositeKey(MetricKind, Key);
7
8impl CompositeKey {
9 pub const fn new(kind: MetricKind, key: Key) -> CompositeKey {
11 CompositeKey(kind, key)
12 }
13
14 pub fn key(&self) -> &Key {
16 &self.1
17 }
18
19 pub fn kind(&self) -> MetricKind {
21 self.0
22 }
23
24 pub fn into_parts(self) -> (MetricKind, Key) {
26 (self.0, self.1)
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use std::cmp::Ordering;
33
34 use metrics::Key;
35
36 use super::*;
37
38 #[test]
39 fn test_same_keys_different_kinds_not_equal() {
40 let key = Key::from_name("test");
41 let key1 = CompositeKey::new(MetricKind::Counter, key.clone());
42 let key2 = CompositeKey::new(MetricKind::Gauge, key);
43
44 assert_ne!(key1.cmp(&key2), Ordering::Equal);
45 }
46}