diff --git a/src/account.rs b/src/account.rs index 9020810..3750458 100644 --- a/src/account.rs +++ b/src/account.rs @@ -88,7 +88,7 @@ impl Account { /// i.e. "Assets:Cash" pub fn find_account(&self, name: &str) -> Option<&Account> { if let Some(ptr) = self.find_or_create(name, false) { - let acct = self.get_account(ptr); + let acct = Account::from_ptr(ptr); return Some(acct); } else { return None; @@ -138,7 +138,7 @@ impl Account { Some(account) } - pub fn get_account(&self, acct_ptr: *const Account) -> &Account { + pub fn from_ptr<'a>(acct_ptr: *const Account) -> &'a Account { unsafe { &*acct_ptr } } diff --git a/src/amount.rs b/src/amount.rs index 60e26c3..8f3cd59 100644 --- a/src/amount.rs +++ b/src/amount.rs @@ -22,7 +22,7 @@ impl Amount { Self { quantity, commodity: if commodity.is_some() { - commodity.unwrap() as *const Commodity + commodity.unwrap() } else { std::ptr::null() }, diff --git a/src/history.rs b/src/history.rs index 4194cd9..d40a6fb 100644 --- a/src/history.rs +++ b/src/history.rs @@ -266,9 +266,9 @@ pub struct Price { } impl Price { - pub fn new(commodity: &Commodity, datetime: NaiveDateTime, cost: Amount) -> Self { + pub fn new(commodity: *const Commodity, datetime: NaiveDateTime, cost: Amount) -> Self { Self { - commodity: commodity as *const Commodity, + commodity, datetime, price: cost, } diff --git a/src/pool.rs b/src/pool.rs index e1f3dbe..a60e62b 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -188,7 +188,7 @@ impl CommodityPool { // self.add_price(amount.commodity_index.unwrap(), moment, per_unit_cost); // Instead, return the new price and have the caller store it. new_price = Some(Price::new( - amount.get_commodity().unwrap(), + amount.commodity, moment, per_unit_cost, ));