aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Ramos2025-02-16 14:11:44 +0100
committerGuillermo Ramos2025-02-16 19:31:48 +0100
commit472b540de459ade8ce8f9b16b97de06020dede30 (patch)
treebde7c112cd7757bd10d348d5ba41a8d83ee29cda
parent87d79dbda299de242aa2a4420df2a447274dc355 (diff)
downloadhiccup-472b540de459ade8ce8f9b16b97de06020dede30.tar.gz
SimUpdates default instead of ::new
-rw-r--r--src/lib.rs17
-rw-r--r--src/main.rs2
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<u32, Vec<&'a SimUpdate>>,
}
-// pub type SimUpdates<'a> = HashMap<u32, &'a SimUpdate>;
-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();