aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorGuillermo Ramos2025-02-16 15:46:01 +0100
committerGuillermo Ramos2025-02-16 19:36:23 +0100
commit209adfe41e976919c290debbfd16cf81f5ba296e (patch)
tree341e1b78a55cf0c9933caa8d7f5fd8bb737ba863 /src/lib.rs
parent7d80d3d2be3e0f8e36be66a08879b1f04a381e88 (diff)
downloadhiccup-209adfe41e976919c290debbfd16cf81f5ba296e.tar.gz
Basic simulation API
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0022703..5eb8b5b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,7 +2,9 @@ use std::collections::HashMap;
use std::fmt;
use std::ops::AddAssign;
-#[derive(Clone, Copy)]
+use serde::Serialize;
+
+#[derive(Clone, Copy, Serialize)]
pub struct Capital {
principal: f64,
interest: f64,
@@ -22,6 +24,7 @@ impl AddAssign for Capital {
}
}
+#[derive(Serialize)]
pub struct Simulation<'a> {
st: SimState,
updates: SimUpdates<'a>,
@@ -140,7 +143,7 @@ impl<'a> Simulation<'a> {
}
}
-#[derive(Clone)]
+#[derive(Clone, Serialize)]
struct SimState {
period: u32,
principal: f64,
@@ -179,7 +182,7 @@ impl SimState {
}
}
-#[derive(Clone)]
+#[derive(Clone, Serialize)]
pub struct Quota {
period: u32,
payed: Capital,
@@ -206,7 +209,7 @@ impl fmt::Display for Quota {
}
}
-#[derive(Debug, Default)]
+#[derive(Debug, Default, Serialize)]
pub struct SimUpdates<'a> {
periodically: Vec<(u32, Vec<&'a SimUpdate>)>,
by_month: HashMap<u32, Vec<&'a SimUpdate>>,
@@ -247,7 +250,7 @@ impl<'a> SimUpdates<'a> {
}
}
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, Serialize)]
pub enum SimUpdate {
Amortize(f64),
}