From 8122e01b1d8d3347b12e892ae7f2d3bd8ed9347b Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 2 Jan 2019 20:43:35 -0500 Subject: [PATCH] clippy: Implement defaults --- ofborg/build.rs | 28 ++++------------------------ ofborg/src/notifyworker.rs | 3 ++- ofborg/src/tagger.rs | 30 ++++++++++++++++++++++++------ 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/ofborg/build.rs b/ofborg/build.rs index 14b6bb8..f130eff 100644 --- a/ofborg/build.rs +++ b/ofborg/build.rs @@ -430,7 +430,7 @@ pub enum Event { // Create a struct to hold all the possible metrics f.write_all( b" -#[derive(Debug, Clone)] +#[derive(Default, Debug, Clone)] pub struct MetricCollector { ", ) @@ -457,32 +457,12 @@ pub struct MetricCollector { // Create a struct to hold all the possible metrics f.write_all( b" + impl MetricCollector { pub fn new() -> MetricCollector { - MetricCollector { -", - ) - .unwrap(); + Default::default() + } - let variants: Vec = events() - .iter() - .map(|mtype| { - let mut fields: Vec = mtype.enum_field_types(); - fields.push("String".to_owned()); // Instance - - format!( - " {}: Arc::new(Mutex::new(HashMap::new()))", - &mtype.metric_name(), - ) - }) - .collect(); - - f.write_all(variants.join(",\n").as_bytes()).unwrap(); - f.write_all("\n }\n".as_bytes()).unwrap(); - f.write_all("\n }\n".as_bytes()).unwrap(); - - f.write_all( - b" pub fn record(&self, instance: String, event: Event) { match event { ", diff --git a/ofborg/src/notifyworker.rs b/ofborg/src/notifyworker.rs index 95ea2ea..a4626e3 100644 --- a/ofborg/src/notifyworker.rs +++ b/ofborg/src/notifyworker.rs @@ -25,13 +25,14 @@ pub trait NotificationReceiver { fn tell(&mut self, action: Action); } +#[derive(Default)] pub struct DummyNotificationReceiver { pub actions: Vec, } impl DummyNotificationReceiver { pub fn new() -> DummyNotificationReceiver { - DummyNotificationReceiver { actions: vec![] } + Default::default() } } diff --git a/ofborg/src/tagger.rs b/ofborg/src/tagger.rs index 5a764ae..d53a2c4 100644 --- a/ofborg/src/tagger.rs +++ b/ofborg/src/tagger.rs @@ -7,8 +7,8 @@ pub struct StdenvTagger { selected: Vec, } -impl StdenvTagger { - pub fn new() -> StdenvTagger { +impl Default for StdenvTagger { + fn default() -> StdenvTagger { let mut t = StdenvTagger { possible: vec![ String::from("10.rebuild-linux-stdenv"), @@ -20,6 +20,12 @@ impl StdenvTagger { t } +} + +impl StdenvTagger { + pub fn new() -> StdenvTagger { + Default::default() + } pub fn changed(&mut self, systems: Vec) { for system in systems { @@ -63,8 +69,8 @@ pub struct PkgsAddedRemovedTagger { selected: Vec, } -impl PkgsAddedRemovedTagger { - pub fn new() -> PkgsAddedRemovedTagger { +impl Default for PkgsAddedRemovedTagger { + fn default() -> PkgsAddedRemovedTagger { let mut t = PkgsAddedRemovedTagger { possible: vec![ String::from("8.has: package (new)"), @@ -76,6 +82,12 @@ impl PkgsAddedRemovedTagger { t } +} + +impl PkgsAddedRemovedTagger { + pub fn new() -> PkgsAddedRemovedTagger { + Default::default() + } pub fn changed(&mut self, removed: &[PackageArch], added: &[PackageArch]) { if !removed.is_empty() { @@ -102,8 +114,8 @@ pub struct RebuildTagger { selected: Vec, } -impl RebuildTagger { - pub fn new() -> RebuildTagger { +impl Default for RebuildTagger { + fn default() -> RebuildTagger { let mut t = RebuildTagger { possible: vec![ String::from("10.rebuild-linux: 501+"), @@ -123,6 +135,12 @@ impl RebuildTagger { t } +} + +impl RebuildTagger { + pub fn new() -> RebuildTagger { + Default::default() + } pub fn parse_attrs(&mut self, attrs: Vec) { let mut counter_darwin = 0;