Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive default instead of obvious manual impl #437

Merged
merged 1 commit into from Mar 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 3 additions & 18 deletions src/registry.rs
Expand Up @@ -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<u64, Box<dyn Collector>>,
pub dim_hashes_by_name: HashMap<String, u64>,
Expand Down Expand Up @@ -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<RwLock<RegistryCore>>,
}

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.
Expand Down