Replace for loops with maps

This commit is contained in:
Wojciech Kozlowski 2018-12-27 02:06:38 +05:30
parent 1f560581b0
commit 676830f211

View File

@ -205,12 +205,10 @@ impl RwmStatus {
/// Return temperature reads from all monitors. /// Return temperature reads from all monitors.
pub fn get_temperatures(&self) -> String { pub fn get_temperatures(&self) -> String {
let mut temp_strs: Vec<String> = vec![]; let temp_strs: Vec<String> = self.hw_mons
.iter()
for hwmon in self.hw_mons.iter() { .map(|hw_mon| get_temp(&hw_mon))
temp_strs.push(get_temp(&hwmon)); .collect();
}
temp_strs.join("|") temp_strs.join("|")
} }
@ -222,25 +220,19 @@ impl RwmStatus {
/// Return battery status for all batteries. /// Return battery status for all batteries.
pub fn get_batteries(&self) -> String { pub fn get_batteries(&self) -> String {
let mut batt_strs: Vec<String> = vec![]; let batt_strs: Vec<String> = self.batts.iter().map(|batt| get_batt(&batt)).collect();
for batt in self.batts.iter() {
batt_strs.push(get_batt(&batt));
}
batt_strs.join("|") batt_strs.join("|")
} }
/// Return times for all configured time zones. /// Return times for all configured time zones.
pub fn get_times(&self) -> String { pub fn get_times(&self) -> String {
let mut tz_strs: Vec<String> = vec![]; let mut tz_strs: Vec<String> = self.tzs
.iter()
for tz in self.tzs.iter() { .map(|tz| {
tz_strs.push(format!("{}:{}", tz.label, get_tz_time(&tz.name, "%H:%M"))); format!("{}:{}", tz.label, get_tz_time(&tz.name, "%H:%M"))
} })
.collect();
tz_strs.push(get_local_time("KW %W %a %d %b %H:%M %Z %Y")); tz_strs.push(get_local_time("KW %W %a %d %b %H:%M %Z %Y"));
tz_strs.join(" ") tz_strs.join(" ")
} }
} }