Crate ledger_rs_lib

Source
Expand description

§Ledger-rs library

Ledger-cli functionality implemented in Rust

Early work-in-progress.

The basic functionality demo:

Given a basic.ledger text file, with the contents

2023-04-21 Supermarket
    Expenses:Food  20 EUR
    Assets:Cash

you can use the library to parse the transactions from the file and provide a basic report on account balances

    let actual = ledger_rs_lib::run_command("b -f tests/basic.ledger");

    assert!(!actual.is_empty());
    assert_eq!(5, actual.len());
    assert_eq!("Account  has balance 0 EUR", actual[0]);
    assert_eq!("Account Assets has balance -20 EUR", actual[1]);
    assert_eq!("Account Assets:Cash has balance -20 EUR", actual[2]);
    assert_eq!("Account Expenses has balance 20 EUR", actual[3]);
    assert_eq!("Account Expenses:Food has balance 20 EUR", actual[4]);

Modules§

account
Account definition and operations
amount
Amount and the Decimal numeric type
commodity
Commodity definition
history
Commodity price history
journal
Journal The main model object. The journal files are parsed into the Journal structure. Provides methods for fetching and iterating over the contained elements (transactions, posts, accounts…).
parser
Parser with iterators
pool
Commodity Pool
post
Posting
report
Reports module containing the report definitions
scanner
Scanner scans the input text and returns tokens (groups of characters) back for parsing. Scans/tokenizes the journal files. There are scanner functions for every element of the journal.
utilities
Handy utility functions
xact
Transaction module

Functions§

parse_file
Parse input and return the model structure.
parse_text
Parses text containing Ledger-style journal. text: &str A Ledger-style journal. The same content that is normally stored in text files journal: &mut Journal The result are stored in the given Journal instance.
parser_experiment
run
An entry point for the CLIs. The commands and arguments sent to the CLI are processed here. This is so that 3rd-party clients can pass argv and get the same result. The arguments should be compatible with Ledger, so that the functionality is comparable.
run_command
A convenient entry point if you want to use a command string directly. command: &str A Ledger-style command, i.e. “balance -f journal.ledger”
wasm_test