clippy: Implement defaults

This commit is contained in:
Graham Christensen 2019-01-02 20:43:35 -05:00
parent 671a9257c9
commit 8122e01b1d
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
3 changed files with 30 additions and 31 deletions

View file

@ -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<String> = events()
.iter()
.map(|mtype| {
let mut fields: Vec<String> = 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 {
",

View file

@ -25,13 +25,14 @@ pub trait NotificationReceiver {
fn tell(&mut self, action: Action);
}
#[derive(Default)]
pub struct DummyNotificationReceiver {
pub actions: Vec<Action>,
}
impl DummyNotificationReceiver {
pub fn new() -> DummyNotificationReceiver {
DummyNotificationReceiver { actions: vec![] }
Default::default()
}
}

View file

@ -7,8 +7,8 @@ pub struct StdenvTagger {
selected: Vec<String>,
}
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<tasks::eval::stdenvs::System>) {
for system in systems {
@ -63,8 +69,8 @@ pub struct PkgsAddedRemovedTagger {
selected: Vec<String>,
}
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<String>,
}
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<PackageArch>) {
let mut counter_darwin = 0;