@@ -226,9 +226,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
226226 /// family.get_or_create(&vec![("method".to_owned(), "GET".to_owned())]).inc();
227227 /// ```
228228 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) {
232230 return metric;
233231 }
234232
@@ -474,34 +472,34 @@ mod tests {
474472 fn test_get ( ) {
475473 let family = Family :: < Vec < ( String , String ) > , Counter > :: default ( ) ;
476474
477- // Test getting a non-existent metric
475+ // Test getting a non-existent metric.
478476 let non_existent = family. get ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] ) ;
479477 assert ! ( non_existent. is_none( ) ) ;
480478
481- // Create a metric
479+ // Create a metric.
482480 family
483481 . get_or_create ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] )
484482 . inc ( ) ;
485483
486- // Test getting an existing metric
484+ // Test getting an existing metric.
487485 let existing = family. get ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] ) ;
488486 assert ! ( existing. is_some( ) ) ;
489487 assert_eq ! ( existing. unwrap( ) . get( ) , 1 ) ;
490488
491- // Test getting a different non-existent metric
489+ // Test getting a different non-existent metric.
492490 let another_non_existent = family. get ( & vec ! [ ( "method" . to_string( ) , "POST" . to_string( ) ) ] ) ;
493491 assert ! ( another_non_existent. is_none( ) ) ;
494492
495- // Test modifying the metric through the returned reference
493+ // Test modifying the metric through the returned reference.
496494 if let Some ( metric) = family. get ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] ) {
497495 metric. inc ( ) ;
498496 }
499497
500- // Verify the modification
498+ // Verify the modification.
501499 let modified = family. get ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] ) ;
502500 assert_eq ! ( modified. unwrap( ) . get( ) , 2 ) ;
503501
504- // Test with a different label set type
502+ // Test with a different label set type.
505503 let string_family = Family :: < String , Counter > :: default ( ) ;
506504 string_family. get_or_create ( & "test" . to_string ( ) ) . inc ( ) ;
507505
0 commit comments