From 991508539f0c410bb818ba342dfe2aebcf8ed0af Mon Sep 17 00:00:00 2001 From: Jaseem Abid Date: Sat, 5 Mar 2022 00:46:03 +0000 Subject: [PATCH] Derive default instead of obvious manual impl Signed-off-by: Jaseem Abid --- src/registry.rs | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/registry.rs b/src/registry.rs index d204d8e0..a4be61f1 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -15,6 +15,7 @@ use crate::proto; use cfg_if::cfg_if; use lazy_static::lazy_static; +#[derive(Default)] struct RegistryCore { pub collectors_by_id: HashMap>, pub dim_hashes_by_name: HashMap, @@ -216,31 +217,15 @@ impl RegistryCore { /// A struct for registering Prometheus collectors, collecting their metrics, and gathering /// them into `MetricFamilies` for exposition. -#[derive(Clone, Debug)] +#[derive(Clone, Default, Debug)] pub struct Registry { r: Arc>, } -impl Default for Registry { - fn default() -> Registry { - let r = RegistryCore { - collectors_by_id: HashMap::new(), - dim_hashes_by_name: HashMap::new(), - desc_ids: HashSet::new(), - labels: None, - prefix: None, - }; - - Registry { - r: Arc::new(RwLock::new(r)), - } - } -} - impl Registry { /// `new` creates a Registry. pub fn new() -> Registry { - Registry::default() + Default::default() } /// Create a new registry, with optional custom prefix and labels.