1use crate::{
2 Cash,
3 HashMap,
4 sanitize_negative,
5};
6
7#[allow(dead_code)]
8
9pub async fn new (currency: &str, amount: f64, allow_negatives: bool) -> Cash {
16 Cash {
17 currency: String::from(currency),
18 amount,
19 allow_negatives,
20 log: HashMap::from([]),
21 newlog: Vec::new(),
22 }
23}
24
25impl Cash {
26 pub fn new (currency: &str, amount: f64, allow_negatives: bool) -> Self {
27 Self {
28 currency: String::from(currency),
29 amount,
30 allow_negatives,
31 log: HashMap::from([]),
32 newlog: Vec::new(),
33 }
34 }
35
36 pub fn create (currency: &str, amount: f64, allow_negatives: bool) -> Self {
37 let new_amount: f64 = if allow_negatives { amount } else { sanitize_negative(amount) };
38
39 match currency {
44 "USD" | "EUR" | "GBP" | "CAD" | "AUD" | "RON" | "JPY" => Self {
45 currency: String::from(currency),
46 amount: new_amount,
47 allow_negatives,
48 log: HashMap::from([]),
49 newlog: vec![],
50 },
51 _ => Self {
53 currency: String::from("USD"),
54 amount: new_amount,
55 allow_negatives,
56 log: HashMap::from([]),
57 newlog: vec![],
58 },
59 }
60 }
61}
62
63pub trait Create {
64 fn currency (&self) -> String;
65 fn amount (&self) -> f64;
66}
67
68impl Create for Cash {
69 fn currency (&self) -> String {
70 String::from(&self.currency)
71 }
72
73 fn amount (&self) -> f64 {
74 self.amount
75 }
76}