diff --git a/src/macros.rs b/src/macros.rs index 1dc9c45f..933198a4 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -213,8 +213,9 @@ fn test_histogram_opts_trailing_comma() { #[macro_export(local_inner_macros)] macro_rules! register_counter { (@of_type $TYPE:ident, $OPTS:expr) => {{ - let counter = $crate::$TYPE::with_opts($OPTS).unwrap(); - $crate::register(Box::new(counter.clone())).map(|_| counter) + $crate::$TYPE::with_opts($OPTS).and_then(|counter| { + $crate::register(Box::new(counter.clone())).map(|_| counter) + }) }}; ($OPTS:expr $(,)?) => {{ @@ -259,8 +260,9 @@ fn test_register_counter_trailing_comma() { #[macro_export(local_inner_macros)] macro_rules! register_counter_with_registry { (@of_type $TYPE: ident, $OPTS:expr, $REGISTRY:expr) => {{ - let counter = $crate::$TYPE::with_opts($OPTS).unwrap(); - $REGISTRY.register(Box::new(counter.clone())).map(|_| counter) + $crate::$TYPE::with_opts($OPTS).and_then(|counter| { + $REGISTRY.register(Box::new(counter.clone())).map(|_| counter) + }) }}; ($OPTS:expr, $REGISTRY:expr $(,)?) => {{ @@ -360,15 +362,19 @@ fn test_register_int_counter() { #[doc(hidden)] macro_rules! __register_counter_vec { ($TYPE:ident, $OPTS:expr, $LABELS_NAMES:expr) => {{ - let counter_vec = $crate::$TYPE::new($OPTS, $LABELS_NAMES).unwrap(); - $crate::register(Box::new(counter_vec.clone())).map(|_| counter_vec) + $crate::$TYPE::new($OPTS, $LABELS_NAMES).and_then(|counter_vec| { + $crate::default_registry() + .register(Box::new(counter_vec.clone())) + .map(|_| counter_vec) + }) }}; ($TYPE:ident, $OPTS:expr, $LABELS_NAMES:expr, $REGISTRY:expr) => {{ - let counter_vec = $crate::$TYPE::new($OPTS, $LABELS_NAMES).unwrap(); - $REGISTRY - .register(Box::new(counter_vec.clone())) - .map(|_| counter_vec) + $crate::$TYPE::new($OPTS, $LABELS_NAMES).and_then(|counter_vec| { + $REGISTRY + .register(Box::new(counter_vec.clone())) + .map(|_| counter_vec) + }) }}; } @@ -542,13 +548,16 @@ fn test_register_int_counter_vec() { #[doc(hidden)] macro_rules! __register_gauge { ($TYPE:ident, $OPTS:expr) => {{ - let gauge = $crate::$TYPE::with_opts($OPTS).unwrap(); - $crate::register(Box::new(gauge.clone())).map(|_| gauge) + $crate::$TYPE::with_opts($OPTS).and_then(|gauge| { + $crate::default_registry() + .register(Box::new(gauge.clone())) + .map(|_| gauge) + }) }}; ($TYPE:ident, $OPTS:expr, $REGISTRY:expr) => {{ - let gauge = $crate::$TYPE::with_opts($OPTS).unwrap(); - $REGISTRY.register(Box::new(gauge.clone())).map(|_| gauge) + $crate::$TYPE::with_opts($OPTS) + .and_then(|gauge| $REGISTRY.register(Box::new(gauge.clone())).map(|_| gauge)) }}; } @@ -669,15 +678,16 @@ macro_rules! register_int_gauge_with_registry { #[doc(hidden)] macro_rules! __register_gauge_vec { ($TYPE:ident, $OPTS:expr, $LABELS_NAMES:expr $(,)?) => {{ - let gauge_vec = $crate::$TYPE::new($OPTS, $LABELS_NAMES).unwrap(); - $crate::register(Box::new(gauge_vec.clone())).map(|_| gauge_vec) + $crate::$TYPE::new($OPTS, $LABELS_NAMES) + .and_then(|gauge_vec| $crate::register(Box::new(gauge_vec.clone())).map(|_| gauge_vec)) }}; ($TYPE:ident, $OPTS:expr, $LABELS_NAMES:expr, $REGISTRY:expr $(,)?) => {{ - let gauge_vec = $crate::$TYPE::new($OPTS, $LABELS_NAMES).unwrap(); - $REGISTRY - .register(Box::new(gauge_vec.clone())) - .map(|_| gauge_vec) + $crate::$TYPE::new($OPTS, $LABELS_NAMES).and_then(|gauge_vec| { + $REGISTRY + .register(Box::new(gauge_vec.clone())) + .map(|_| gauge_vec) + }) }}; } @@ -916,8 +926,8 @@ macro_rules! register_histogram { }; ($HOPTS:expr $(,)?) => {{ - let histogram = $crate::Histogram::with_opts($HOPTS).unwrap(); - $crate::register(Box::new(histogram.clone())).map(|_| histogram) + $crate::Histogram::with_opts($HOPTS) + .and_then(|histogram| $crate::register(Box::new(histogram.clone())).map(|_| histogram)) }}; } @@ -971,10 +981,11 @@ macro_rules! register_histogram_with_registry { }; ($HOPTS:expr, $REGISTRY:expr $(,)?) => {{ - let histogram = $crate::Histogram::with_opts($HOPTS).unwrap(); - $REGISTRY - .register(Box::new(histogram.clone())) - .map(|_| histogram) + $crate::Histogram::with_opts($HOPTS).and_then(|histogram| { + $REGISTRY + .register(Box::new(histogram.clone())) + .map(|_| histogram) + }) }}; } @@ -1029,8 +1040,9 @@ fn test_register_histogram_with_registry_trailing_comma() { #[macro_export(local_inner_macros)] macro_rules! register_histogram_vec { ($HOPTS:expr, $LABELS_NAMES:expr $(,)?) => {{ - let histogram_vec = $crate::HistogramVec::new($HOPTS, $LABELS_NAMES).unwrap(); - $crate::register(Box::new(histogram_vec.clone())).map(|_| histogram_vec) + $crate::HistogramVec::new($HOPTS, $LABELS_NAMES).and_then(|histogram_vec| { + $crate::register(Box::new(histogram_vec.clone())).map(|_| histogram_vec) + }) }}; ($NAME:expr, $HELP:expr, $LABELS_NAMES:expr $(,)?) => {{ @@ -1091,10 +1103,11 @@ fn test_register_histogram_vec_trailing_comma() { #[macro_export(local_inner_macros)] macro_rules! register_histogram_vec_with_registry { ($HOPTS:expr, $LABELS_NAMES:expr, $REGISTRY:expr $(,)?) => {{ - let histogram_vec = $crate::HistogramVec::new($HOPTS, $LABELS_NAMES).unwrap(); - $REGISTRY - .register(Box::new(histogram_vec.clone())) - .map(|_| histogram_vec) + $crate::HistogramVec::new($HOPTS, $LABELS_NAMES).and_then(|histogram_vec| { + $REGISTRY + .register(Box::new(histogram_vec.clone())) + .map(|_| histogram_vec) + }) }}; ($NAME:expr, $HELP:expr, $LABELS_NAMES:expr, $REGISTRY:expr $(,)?) => {{