Skip to content

Commit 7d5e5cc

Browse files
committed
review: rename method to get_or_create_owned()
prometheus#244 (comment) Signed-off-by: katelyn martin <[email protected]>
1 parent 5b097b0 commit 7d5e5cc

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/metrics/family.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ where
222222
/// let family = Family::<Vec<(String, String)>, Counter>::default();
223223
///
224224
/// // Will create and return the metric with label `method="GET"` when first called.
225-
/// family.get_or_create_clone(&vec![("method".to_owned(), "GET".to_owned())]).inc();
225+
/// family.get_or_create_owned(&vec![("method".to_owned(), "GET".to_owned())]).inc();
226226
///
227227
/// // Will return a clone of the existing metric on all subsequent calls.
228-
/// family.get_or_create_clone(&vec![("method".to_owned(), "GET".to_owned())]).inc();
228+
/// family.get_or_create_owned(&vec![("method".to_owned(), "GET".to_owned())]).inc();
229229
/// ```
230230
///
231231
/// Callers wishing to avoid a clone of the metric `M` can call [`Family::get_or_create()`] to
232232
/// return a reference to the metric instead.
233-
pub fn get_or_create_clone(&self, label_set: &S) -> M {
233+
pub fn get_or_create_owned(&self, label_set: &S) -> M {
234234
use std::ops::Deref;
235235

236236
let guard = self.get_or_create(label_set);
@@ -261,7 +261,7 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
261261
/// ```
262262
///
263263
/// NB: This method can cause deadlocks if multiple metrics within this family are read at
264-
/// once. Use [`Family::get_or_create_clone()`] if you would like to avoid this by cloning the
264+
/// once. Use [`Family::get_or_create_owned()`] if you would like to avoid this by cloning the
265265
/// metric `M`.
266266
pub fn get_or_create(&self, label_set: &S) -> MappedRwLockReadGuard<M> {
267267
if let Some(metric) = self.get(label_set) {
@@ -549,7 +549,7 @@ mod tests {
549549
assert!(non_existent_string.is_none());
550550
}
551551

552-
/// Tests that [`Family::get_or_create_clone()`] does not cause deadlocks.
552+
/// Tests that [`Family::get_or_create_owned()`] does not cause deadlocks.
553553
#[test]
554554
fn counter_family_does_not_deadlock() {
555555
/// A structure we'll place two counters into, within a single expression.
@@ -560,8 +560,8 @@ mod tests {
560560

561561
let family = Family::<(&str, &str), Counter>::default();
562562
let s = S {
563-
apples: family.get_or_create_clone(&("kind", "apple")),
564-
oranges: family.get_or_create_clone(&("kind", "orange")),
563+
apples: family.get_or_create_owned(&("kind", "apple")),
564+
oranges: family.get_or_create_owned(&("kind", "orange")),
565565
};
566566

567567
s.apples.inc();

0 commit comments

Comments
 (0)