1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4use serde_json;
5
6use super::Input;
7
8#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
10pub struct Inputs {
11 inputs_list: Vec<Input>,
12 total_balance: i64,
13}
14
15impl fmt::Display for Inputs {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 write!(
18 f,
19 "{}",
20 serde_json::to_string_pretty(self).unwrap_or_default()
21 )
22 }
23}
24
25impl Inputs {
26 pub fn inputs_list(&self) -> &[Input] {
28 &self.inputs_list
29 }
30
31 pub fn inputs_list_mut(&mut self) -> &mut [Input] {
33 &mut self.inputs_list
34 }
35
36 pub fn set_inputs_list(&mut self, new_value: impl Into<Vec<Input>>) {
38 self.inputs_list = new_value.into();
39 }
40
41 pub fn add(&mut self, new_value: impl Into<Input>) {
43 self.inputs_list.push(new_value.into());
44 }
45
46 pub fn total_balance(&self) -> i64 {
48 self.total_balance
49 }
50
51 pub fn total_balance_mut(&mut self) -> &mut i64 {
53 &mut self.total_balance
54 }
55
56 pub fn set_total_balance(&mut self, new_value: impl Into<i64>) {
58 self.total_balance = new_value.into();
59 }
60}