From 472b540de459ade8ce8f9b16b97de06020dede30 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Sun, 16 Feb 2025 14:11:44 +0100 Subject: SimUpdates default instead of ::new --- src/lib.rs | 17 +++++------------ src/main.rs | 2 +- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e523ee1..0022703 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -59,7 +59,7 @@ impl<'a> Simulation<'a> { }, payed_amortized: 0., history: vec![], - updates: SimUpdates::new(), + updates: SimUpdates::default(), } } @@ -206,20 +206,13 @@ impl fmt::Display for Quota { } } -#[derive(Debug)] +#[derive(Debug, Default)] pub struct SimUpdates<'a> { periodically: Vec<(u32, Vec<&'a SimUpdate>)>, by_month: HashMap>, } -// pub type SimUpdates<'a> = HashMap; -impl<'a> SimUpdates<'a> { - pub fn new() -> Self { - SimUpdates { - periodically: vec![], - by_month: HashMap::new(), - } - } +impl<'a> SimUpdates<'a> { fn get(&self, month: u32) -> Vec<&'a SimUpdate> { let SimUpdates { periodically, @@ -272,13 +265,13 @@ impl fmt::Display for SimUpdate { impl SimUpdate { pub fn every(&self, months: u32) -> SimUpdates { - let mut updates = SimUpdates::new(); + let mut updates = SimUpdates::default(); updates.periodically.push((months, vec![self])); updates } pub fn at(&self, month: u32) -> SimUpdates { - let mut updates = SimUpdates::new(); + let mut updates = SimUpdates::default(); updates.by_month.insert(month, vec![self]); updates } diff --git a/src/main.rs b/src/main.rs index 80d7ae7..5ca388b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ fn main() { let updates: SimUpdates = Amortize(12_000.).every(12).and(Amortize(30_000.).at(1)); // let mut sim = Simulation::new(200_000., 0.01621, 30); - // let updates: SimUpdates = SimUpdates::new(); + // let updates: SimUpdates = SimUpdates::default(); sim.run(updates); sim.render_table(); -- cgit v1.2.3