Crate rgnucash

Crate rgnucash 

Source
Expand description

§gnucash-sys

FFI bindings and safe Rust wrappers for the GnuCash engine library.

This crate provides low-level bindings to libgnucash, allowing Rust programs to interact with GnuCash’s accounting engine.

§Core Types

The library provides safe wrappers around GnuCash’s core entity types:

  • Book - Top-level container for all financial data
  • Account - Hierarchical ledger for tracking splits
  • Transaction - Double-entry accounting record
  • Split - Single entry in a transaction
  • Guid - 128-bit unique identifier
  • Numeric - Rational number (numerator/denominator)

§Example

use gnucash_sys::{Book, Account, Transaction, Split, Numeric, GNCAccountType};

// Create a new book
let book = Book::new();

// Create accounts
let root = Account::new(&book);
root.begin_edit();
root.set_name("Root");
root.set_type(GNCAccountType::ACCT_TYPE_ROOT);
root.commit_edit();

let checking = Account::new(&book);
checking.begin_edit();
checking.set_name("Checking");
checking.set_type(GNCAccountType::ACCT_TYPE_BANK);
checking.commit_edit();
root.append_child(&checking);

// Create a transaction with splits
let txn = Transaction::new(&book);
txn.begin_edit();
txn.set_description("Opening balance");
txn.set_date(1, 1, 2024);

let split = Split::new(&book);
split.set_account(&checking);
split.set_transaction(&txn);
split.set_amount(Numeric::new(10000, 100)); // $100.00
split.set_value(Numeric::new(10000, 100));

txn.commit_edit();

// Iterate over account children
for child in root.children() {
    println!("Child account: {:?}", child.name());
}

// Iterate over transaction splits
for split in txn.splits() {
    println!("Split amount: {:?}", split.amount());
}

§Building

This crate requires:

  • GnuCash source code (set GNUCASH_SRC env var, default: ../gnucash)
  • GnuCash built (set GNUCASH_BUILD env var, default: ../gnucash/build)
  • glib-2.0 development libraries

§Safety

The safe wrappers handle memory management via RAII (Drop trait), but the underlying GnuCash library is not thread-safe. While the wrapper types implement Send, concurrent access requires external synchronization.

Re-exports§

pub use account::Account;
pub use account::GNCAccountType;
pub use book::Book;
pub use error::Error;
pub use error::Result;
pub use iter::AccountChildren;
pub use iter::AccountDescendants;
pub use iter::AccountSplits;
pub use iter::TransactionSplits;
pub use split::Split;
pub use transaction::Transaction;
pub use types::Guid;
pub use types::Numeric;
pub use types::GUID_ENCODING_LENGTH;
pub use session::init_engine;
pub use session::is_engine_initialized;
pub use session::QofBackendError;
pub use session::Session;
pub use session::SessionOpenMode;
pub use split::reconcile;
pub use transaction::txn_type;
pub use price::Price;
pub use price::PriceDB;
pub use price::PriceSource;

Modules§

account
Safe wrapper for Account. Safe wrapper for GnuCash Account.
book
Safe wrapper for QofBook. Safe wrapper for QofBook.
error
Error types for gnucash-sys operations. Error types for gnucash-sys.
ffi
Raw FFI bindings generated by bindgen.
iter
Iterators for GnuCash collections. Iterators for GnuCash collections.
price
Safe wrappers for Price and PriceDB. Safe wrappers for GnuCash Price and PriceDB.
session
Safe wrapper for QofSession. Safe wrapper for QofSession - connection to a GnuCash data store.
split
Safe wrapper for Split. Safe wrapper for GnuCash Split.
transaction
Safe wrapper for Transaction. Safe wrapper for GnuCash Transaction.
types
Safe Rust wrappers for core types (Guid, Numeric). Safe Rust wrappers for GnuCash core types.