@@ -226,9 +226,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
226
226
/// family.get_or_create(&vec![("method".to_owned(), "GET".to_owned())]).inc();
227
227
/// ```
228
228
pub fn get_or_create ( & self , label_set : & S ) -> MappedRwLockReadGuard < M > {
229
- if let Ok ( metric) =
230
- RwLockReadGuard :: try_map ( self . metrics . read ( ) , |metrics| metrics. get ( label_set) )
231
- {
229
+ if let Some ( metric) = self . get ( label_set) {
232
230
return metric;
233
231
}
234
232
@@ -474,34 +472,34 @@ mod tests {
474
472
fn test_get ( ) {
475
473
let family = Family :: < Vec < ( String , String ) > , Counter > :: default ( ) ;
476
474
477
- // Test getting a non-existent metric
475
+ // Test getting a non-existent metric.
478
476
let non_existent = family. get ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] ) ;
479
477
assert ! ( non_existent. is_none( ) ) ;
480
478
481
- // Create a metric
479
+ // Create a metric.
482
480
family
483
481
. get_or_create ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] )
484
482
. inc ( ) ;
485
483
486
- // Test getting an existing metric
484
+ // Test getting an existing metric.
487
485
let existing = family. get ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] ) ;
488
486
assert ! ( existing. is_some( ) ) ;
489
487
assert_eq ! ( existing. unwrap( ) . get( ) , 1 ) ;
490
488
491
- // Test getting a different non-existent metric
489
+ // Test getting a different non-existent metric.
492
490
let another_non_existent = family. get ( & vec ! [ ( "method" . to_string( ) , "POST" . to_string( ) ) ] ) ;
493
491
assert ! ( another_non_existent. is_none( ) ) ;
494
492
495
- // Test modifying the metric through the returned reference
493
+ // Test modifying the metric through the returned reference.
496
494
if let Some ( metric) = family. get ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] ) {
497
495
metric. inc ( ) ;
498
496
}
499
497
500
- // Verify the modification
498
+ // Verify the modification.
501
499
let modified = family. get ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] ) ;
502
500
assert_eq ! ( modified. unwrap( ) . get( ) , 2 ) ;
503
501
504
- // Test with a different label set type
502
+ // Test with a different label set type.
505
503
let string_family = Family :: < String , Counter > :: default ( ) ;
506
504
string_family. get_or_create ( & "test" . to_string ( ) ) . inc ( ) ;
507
505
0 commit comments