ledger-utils

Crates.ioledger-utils
lib.rsledger-utils
version0.6.0
sourcesrc
created_at2022-01-04 12:18:08.868971
updated_at2024-03-14 10:10:34.325151
descriptionLedger-cli (https://www.ledger-cli.org/) file processing Rust library, useful for calculating balances, creating reports etc.
homepage
repositoryhttps://github.com/marek-g/rust-ledger-utils
max_upload_size
id507765
size88,259
Marek Gibek (marek-g)

documentation

https://docs.rs/ledger-utils

README

ledger-utils

Crates.io Version Docs.rs Version License Unlicense

Ledger-cli file processing Rust library, useful for calculating balances, creating reports etc.

use anyhow::{bail, Result};
use ledger_utils::{balance::Balance, Ledger};

fn main() -> Result<()> {
    let ledger: Ledger = fs::read_to_string("finances.ledger")?.parse()?;

    if ledger.transactions.is_empty() {
        bail!("no transactions found");
    }

    let balance: Balance = (&ledger).into();

    let mut assets: Vec<_> = balance
        .account_balances
        .iter()
        .filter(|(name, _)| name.starts_with("Assets:"))
        .collect();
    assets.sort_by_key(|&(name, _)| name);
    for (name, balance) in assets {
        println!("{}: {}", name, balance);
    }

    Ok(())
}
Commit count: 22

cargo fmt