@@ -7,7 +7,7 @@ use crate::encoding::{EncodeLabelSet, EncodeMetric, MetricEncoder};
7
7
use super :: { MetricType , TypedMetric } ;
8
8
use parking_lot:: { MappedRwLockReadGuard , RwLock , RwLockReadGuard , RwLockWriteGuard } ;
9
9
use std:: cell:: RefCell ;
10
- use std:: collections:: HashMap ;
10
+ use std:: collections:: BTreeMap ;
11
11
use std:: sync:: Arc ;
12
12
13
13
/// Representation of the OpenMetrics *MetricFamily* data type.
@@ -69,12 +69,12 @@ use std::sync::Arc;
69
69
/// # use std::io::Write;
70
70
/// #
71
71
/// # let mut registry = Registry::default();
72
- /// #[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)]
72
+ /// #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord , EncodeLabelSet)]
73
73
/// struct Labels {
74
74
/// method: Method,
75
75
/// };
76
76
///
77
- /// #[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelValue)]
77
+ /// #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord , EncodeLabelValue)]
78
78
/// enum Method {
79
79
/// GET,
80
80
/// PUT,
@@ -100,9 +100,8 @@ use std::sync::Arc;
100
100
/// # "# EOF\n";
101
101
/// # assert_eq!(expected, buffer);
102
102
/// ```
103
- // TODO: Consider exposing hash algorithm.
104
103
pub struct Family < S , M , C = fn ( ) -> M > {
105
- metrics : Arc < RwLock < HashMap < S , M > > > ,
104
+ metrics : Arc < RwLock < BTreeMap < S , M > > > ,
106
105
/// Function that when called constructs a new metric.
107
106
///
108
107
/// For most metric types this would simply be its [`Default`]
@@ -169,7 +168,7 @@ impl<M, F: Fn() -> M> MetricConstructor<M> for F {
169
168
}
170
169
}
171
170
172
- impl < S : Clone + std :: hash :: Hash + Eq , M : Default > Default for Family < S , M > {
171
+ impl < S : Clone + Eq , M : Default > Default for Family < S , M > {
173
172
fn default ( ) -> Self {
174
173
Self {
175
174
metrics : Arc :: new ( RwLock :: new ( Default :: default ( ) ) ) ,
@@ -178,7 +177,7 @@ impl<S: Clone + std::hash::Hash + Eq, M: Default> Default for Family<S, M> {
178
177
}
179
178
}
180
179
181
- impl < S : Clone + std :: hash :: Hash + Eq , M , C > Family < S , M , C > {
180
+ impl < S : Clone + Eq , M , C > Family < S , M , C > {
182
181
/// Create a metric family using a custom constructor to construct new
183
182
/// metrics.
184
183
///
@@ -208,7 +207,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C> Family<S, M, C> {
208
207
}
209
208
}
210
209
211
- impl < S : Clone + std :: hash :: Hash + Eq , M , C : MetricConstructor < M > > Family < S , M , C > {
210
+ impl < S : Clone + Eq + Ord , M , C : MetricConstructor < M > > Family < S , M , C > {
212
211
/// Access a metric with the given label set, creating it if one does not
213
212
/// yet exist.
214
213
///
@@ -289,7 +288,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
289
288
self . metrics . write ( ) . clear ( )
290
289
}
291
290
292
- pub ( crate ) fn read ( & self ) -> RwLockReadGuard < HashMap < S , M > > {
291
+ pub ( crate ) fn read ( & self ) -> RwLockReadGuard < BTreeMap < S , M > > {
293
292
self . metrics . read ( )
294
293
}
295
294
}
@@ -309,7 +308,7 @@ impl<S, M: TypedMetric, C> TypedMetric for Family<S, M, C> {
309
308
310
309
impl < S , M , C > EncodeMetric for Family < S , M , C >
311
310
where
312
- S : Clone + std :: hash :: Hash + Eq + EncodeLabelSet ,
311
+ S : Clone + Eq + Ord + EncodeLabelSet ,
313
312
M : EncodeMetric + TypedMetric ,
314
313
C : MetricConstructor < M > ,
315
314
{
0 commit comments