Skip to content

Commit

Permalink
returning a reference to the Xact
Browse files Browse the repository at this point in the history
  • Loading branch information
alensiljak committed Aug 8, 2023
1 parent cb29462 commit 1c8b460
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ impl Journal {
self.accounts.len() - 1
}

pub fn add_xact(&mut self, xact: Xact) -> XactIndex {
pub fn add_xact(&mut self, xact: Xact) -> &Xact {
self.xacts.push(xact);
self.xacts.len() - 1
//self.xacts.len() - 1
self.xacts.last().unwrap()
}

pub fn all_posts(&self) -> Vec<&Post> {
Expand Down
7 changes: 3 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<'j, T: Read> Parser<'j, T> {

'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' => {
// Starts with date/number.
self.xact_directive();
let _ = self.xact_directive();
}

' ' | '\t' => {
Expand Down Expand Up @@ -248,11 +248,10 @@ impl<'j, T: Read> Parser<'j, T> {
let tokens = scanner::tokenize_xact_header(&self.buffer);
let xact = Xact::create(tokens[0], tokens[1], tokens[2], tokens[3]);

let ptr = &xact as *const Xact;
// Add xact to the journal
self.journal.add_xact(xact);
let new_ref = self.journal.add_xact(xact);

ptr
new_ref
}

fn xact_directive(&mut self) -> Result<(), Error> {
Expand Down

0 comments on commit 1c8b460

Please sign in to comment.