display moved to function

This commit is contained in:
JasterV 2021-07-29 03:16:47 +02:00
parent cc9eacbeec
commit 86ae78bd83
2 changed files with 29 additions and 8 deletions

View file

@ -23,7 +23,7 @@ async fn main() -> Result<()> {
while let Some(record) = records.next().await {
let transaction = record?;
if addr_map.contains_key(&transaction.client) {
addr_map.get(&transaction.client).unwrap().do_send::<Command>(transaction.into());
} else {
@ -33,12 +33,23 @@ async fn main() -> Result<()> {
addr.do_send::<Command>(transaction.into());
}
}
let mut result: Vec<Account> = vec![];
for addr in addr_map.values() {
let account: Account = addr.send(Stop).await?;
result.push(account);
}
fetch_and_display_accounts(&addr_map).await?;
Ok(())
}
async fn fetch_and_display_accounts(actors: &AccountActors) -> Result<()> {
println!("client,available,held,total,locked");
for addr in actors.values() {
let account: Account = addr.send(Stop).await?;
println!(
"{},{},{},{},{}",
account.get_client(),
account.get_available(),
account.get_held(),
account.get_total(),
account.get_locked()
)
}
Ok(())
}

View file

@ -23,6 +23,16 @@ impl Account {
}
}
pub fn get_client(&self) -> u16 { self.client }
pub fn get_available(&self) -> f32 { self.available }
pub fn get_held(&self) -> f32 { self.held }
pub fn get_total(&self) -> f32 { self.total }
pub fn get_locked(&self) -> bool { self.locked }
pub fn deposit(&mut self, amount: f32) -> Result<()> {
self.assert_lock()?;
self.available += amount;