Skip to content

Commit

Permalink
extracting the from_ptr static method
Browse files Browse the repository at this point in the history
  • Loading branch information
alensiljak committed Sep 7, 2023
1 parent 0adb3da commit 47a90e5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 }
}

Expand Down
2 changes: 1 addition & 1 deletion src/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Amount {
Self {
quantity,
commodity: if commodity.is_some() {
commodity.unwrap() as *const Commodity
commodity.unwrap()
} else {
std::ptr::null()
},
Expand Down
4 changes: 2 additions & 2 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
Expand Down

0 comments on commit 47a90e5

Please sign in to comment.