From b589486472da17313d2e567a9a7f0ad3d1f312b0 Mon Sep 17 00:00:00 2001 From: jake Date: Fri, 18 Jun 2021 12:45:00 -0600 Subject: [PATCH] lint src/ship/drops/* --- src/ship/drops/box_drop_table.rs | 2 +- src/ship/drops/generic_weapon.rs | 18 ++++++------------ src/ship/drops/mod.rs | 2 +- src/ship/drops/rare_drop_table.rs | 21 ++++++++++----------- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/ship/drops/box_drop_table.rs b/src/ship/drops/box_drop_table.rs index 94abd84..f507d27 100644 --- a/src/ship/drops/box_drop_table.rs +++ b/src/ship/drops/box_drop_table.rs @@ -170,7 +170,7 @@ impl BoxDropTable { else { None } - }).nth(0) + }).next() } fn random_box_drop(&self, map_area: &MapArea, rng: &mut R) -> Option { diff --git a/src/ship/drops/generic_weapon.rs b/src/ship/drops/generic_weapon.rs index 71e578c..28a5007 100644 --- a/src/ship/drops/generic_weapon.rs +++ b/src/ship/drops/generic_weapon.rs @@ -266,30 +266,24 @@ impl AttributeTable { fn attributes(&self, percent_pattern: &AttributePercentPattern, attribute_rate: &AttributeRate, rng: &mut R) -> [Option; 3] { let mut percents = vec![ percent_pattern.attribute1.and_then(|pattern_type| { - self.generate_attribute(&pattern_type, &attribute_rate, rng) + self.generate_attribute(&pattern_type, attribute_rate, rng) }), percent_pattern.attribute2.and_then(|pattern_type| { - self.generate_attribute(&pattern_type, &attribute_rate, rng) + self.generate_attribute(&pattern_type, attribute_rate, rng) }), percent_pattern.attribute3.and_then(|pattern_type| { - self.generate_attribute(&pattern_type, &attribute_rate, rng) + self.generate_attribute(&pattern_type, attribute_rate, rng) }), ]; percents.sort_by_key(|p| { - match p { - Some(a) => Some(a.attr), - None => None, - } + p.as_ref().map(|a| a.attr) }); percents.dedup_by_key(|p| { - match p { - Some(a) => Some(a.attr), - None => None, - } + p.as_ref().map(|a| a.attr) }); percents.iter() .fold(([None; 3], 0), |(mut acc, index), p| { // one day I'll be able to collece into an array - if let Some(_) = p { + if p.is_some() { acc[index] = *p; (acc, index + 1) } diff --git a/src/ship/drops/mod.rs b/src/ship/drops/mod.rs index edfa8db..8de0408 100644 --- a/src/ship/drops/mod.rs +++ b/src/ship/drops/mod.rs @@ -152,7 +152,7 @@ impl DropTable { return None; } - if let Some(item) = self.rare_table.get_drop(map_area, &monster, &mut self.rng) { + if let Some(item) = self.rare_table.get_drop(map_area, monster, &mut self.rng) { return Some(item); } diff --git a/src/ship/drops/rare_drop_table.rs b/src/ship/drops/rare_drop_table.rs index df9ec8d..0ca356c 100644 --- a/src/ship/drops/rare_drop_table.rs +++ b/src/ship/drops/rare_drop_table.rs @@ -30,19 +30,18 @@ pub enum RareDropItem { impl RareDropItem { pub fn from_string(name: String) -> RareDropItem { let parse_funcs: [Box Option>; 6] = [ - Box::new(|i| Some(RareDropItem::Weapon(str::parse::(&i).ok()?))), - Box::new(|i| Some(RareDropItem::Armor(str::parse::(&i).ok()?))), - Box::new(|i| Some(RareDropItem::Shield(str::parse::(&i).ok()?))), - Box::new(|i| Some(RareDropItem::Unit(str::parse::(&i).ok()?))), - Box::new(|i| Some(RareDropItem::Tool(str::parse::(&i).ok()?))), - Box::new(|i| Some(RareDropItem::Mag(str::parse::(&i).ok()?))), + Box::new(|i| Some(RareDropItem::Weapon(str::parse::(i).ok()?))), + Box::new(|i| Some(RareDropItem::Armor(str::parse::(i).ok()?))), + Box::new(|i| Some(RareDropItem::Shield(str::parse::(i).ok()?))), + Box::new(|i| Some(RareDropItem::Unit(str::parse::(i).ok()?))), + Box::new(|i| Some(RareDropItem::Tool(str::parse::(i).ok()?))), + Box::new(|i| Some(RareDropItem::Mag(str::parse::(i).ok()?))), ]; for parse in parse_funcs.iter() { - match parse(&name) { - Some(k) => return k, - None => {}, - } + if let Some (k) = parse(&name) { + return k + } } panic!() @@ -151,7 +150,7 @@ impl RareDropTable { else { None } - }).nth(0) + }).next() }) } }