From c3a2ece1e259ff3d0251fefe16cc7a422ddca0ad Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Fri, 14 Mar 2025 11:52:09 +0100 Subject: Minucias minucias --- src/lib.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'src/lib.rs') 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, - by_month: HashMap>, + by_month: HashMap, } 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 } } -- cgit v1.2.3