Skip to content

Commit 6cfacdd

Browse files
authored
Derive default instead of obvious manual impl (#437)
Signed-off-by: Jaseem Abid <[email protected]>
1 parent 117b0df commit 6cfacdd

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/registry.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::proto;
1515
use cfg_if::cfg_if;
1616
use lazy_static::lazy_static;
1717

18+
#[derive(Default)]
1819
struct RegistryCore {
1920
pub collectors_by_id: HashMap<u64, Box<dyn Collector>>,
2021
pub dim_hashes_by_name: HashMap<String, u64>,
@@ -216,31 +217,15 @@ impl RegistryCore {
216217

217218
/// A struct for registering Prometheus collectors, collecting their metrics, and gathering
218219
/// them into `MetricFamilies` for exposition.
219-
#[derive(Clone, Debug)]
220+
#[derive(Clone, Default, Debug)]
220221
pub struct Registry {
221222
r: Arc<RwLock<RegistryCore>>,
222223
}
223224

224-
impl Default for Registry {
225-
fn default() -> Registry {
226-
let r = RegistryCore {
227-
collectors_by_id: HashMap::new(),
228-
dim_hashes_by_name: HashMap::new(),
229-
desc_ids: HashSet::new(),
230-
labels: None,
231-
prefix: None,
232-
};
233-
234-
Registry {
235-
r: Arc::new(RwLock::new(r)),
236-
}
237-
}
238-
}
239-
240225
impl Registry {
241226
/// `new` creates a Registry.
242227
pub fn new() -> Registry {
243-
Registry::default()
228+
Default::default()
244229
}
245230

246231
/// Create a new registry, with optional custom prefix and labels.

0 commit comments

Comments
 (0)