aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 597a360..6d95ff4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -225,7 +225,7 @@ pub struct PeriodicUpdate {
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct SimUpdates {
periodically: Vec<PeriodicUpdate>,
- by_month: HashMap<u32, Vec<SimUpdate>>,
+ by_month: HashMap<u32, SimUpdate>,
}
impl SimUpdates {
@@ -236,16 +236,20 @@ impl SimUpdates {
} = self;
let mut ret = vec![];
- for PeriodicUpdate{period, from, to, update} in periodically.iter() {
+ for PeriodicUpdate {
+ period,
+ from,
+ to,
+ update,
+ } in periodically.iter()
+ {
let base = from.unwrap_or(0);
- if month % period == base && base <= month && to.unwrap_or(month+1) > month {
+ if month % period == base && base <= month && to.unwrap_or(month + 1) > month {
ret.push(*update);
}
}
- if let Some(updates) = by_month.get(&month) {
- for update in updates.iter() {
- ret.push(*update);
- }
+ if let Some(update) = by_month.get(&month) {
+ ret.push(*update);
}
// println!(" {self:?}.get({month}) -> {ret:?}");
ret
@@ -285,13 +289,18 @@ impl fmt::Display for SimUpdate {
impl SimUpdate {
pub fn every(&self, months: u32) -> SimUpdates {
let mut updates = SimUpdates::default();
- updates.periodically.push(PeriodicUpdate{period: months, from: None, to: None, update: *self});
+ updates.periodically.push(PeriodicUpdate {
+ period: months,
+ from: None,
+ to: None,
+ update: *self,
+ });
updates
}
pub fn at(&self, month: u32) -> SimUpdates {
let mut updates = SimUpdates::default();
- updates.by_month.insert(month, vec![*self]);
+ updates.by_month.insert(month, *self);
updates
}
}