Skip to content

Commit 3ac6a03

Browse files
Update main.rs
1 parent a5a24d0 commit 3ac6a03

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
use comfy_table::presets::UTF8_FULL;
12
use comfy_table::Table;
3+
use comfy_table::TableComponent::*;
24

35
struct Asset {
46
ticker: String,
57
buy_price_cents: u32,
8+
// technically we don't care about the current price if it is sold, but it is still a valid property to have, so we include it here, although it isn't displayed
69
current_price_cents: u32,
710
// if sell price is None, it isn't sold
811
sell_price_cents: Option<u32>,
912
}
1013

1114
fn is_asset_sold(asset: &Asset) -> bool {
15+
// if there is no sell price, then it isn't sold (i.e., it is currently held)
1216
match asset.sell_price_cents {
1317
Some(_x) => true,
1418
None => false,
@@ -30,6 +34,12 @@ fn format_money(cents: u32) -> String {
3034

3135
fn print_assets(assets: &[Asset]) {
3236
let mut table = Table::new();
37+
38+
// I prefer a Unicode table with solid lines
39+
table.load_preset(UTF8_FULL);
40+
table.set_style(VerticalLines, '│');
41+
table.set_style(HorizontalLines, '─');
42+
3343
table.set_header(vec![
3444
"Ticker",
3545
"Buy Price",
@@ -80,13 +90,13 @@ fn main() {
8090
Asset {
8191
ticker: "MSFT".to_string(),
8292
buy_price_cents: 1000,
83-
current_price_cents: (25000),
93+
current_price_cents: 25000,
8494
sell_price_cents: None,
8595
},
8696
Asset {
8797
ticker: "APPL".to_string(),
8898
buy_price_cents: 30000,
89-
current_price_cents: (10000000),
99+
current_price_cents: 10000000,
90100
sell_price_cents: Some(40000),
91101
},
92102
];

0 commit comments

Comments
 (0)