pub struct Ledger {
pub directives: Vec<Spanned<Directive>>,
pub options: Options,
pub plugins: Vec<Plugin>,
pub source_map: SourceMap,
pub errors: Vec<LedgerError>,
pub display_context: DisplayContext,
}Expand description
A fully processed ledger.
This is the result of loading and processing a beancount file,
equivalent to the tuple returned by Python’s loader.load_file().
Fields§
§directives: Vec<Spanned<Directive>>Processed directives in source-faithful form: sorted by date,
booked (cost specs resolved, interpolations applied), and
plugin-rewritten. Pad directives remain as Pad; they
are not pre-expanded into synthesized transactions.
Consumers split into two groups:
- Source-faithful consumers (stats, journal, formatter,
LSP, BQL
FROM #entries WHERE type = 'pad'audits, source-mapped diagnostics) iterate this field directly. Pads count as Pads. - Balance-computing consumers (holdings, balances,
balsheet, networth, income, FFI
query.execute/batch, WASMexpandPads/query) callLedger::balance_viewto get the directive stream MERGED with synthesized P-flag transactions for each pad-balance pair. This is the only way to get pad effects into per-account inventory math.
The two views are derived from the same source; there is no
drift possible because Ledger::balance_view is a pure
function of self.directives.
options: OptionsOptions parsed from the file.
plugins: Vec<Plugin>Plugins declared in the file.
source_map: SourceMapSource map for error reporting.
errors: Vec<LedgerError>Errors encountered during processing.
display_context: DisplayContextDisplay context for formatting numbers.
Implementations§
Source§impl Ledger
impl Ledger
Sourcepub fn balance_view(&self) -> Vec<Directive>
pub fn balance_view(&self) -> Vec<Directive>
Return the directive stream merged with synthesized pad-equivalent transactions, suitable for inventory / balance math.
For each Pad directive followed (in date order) by a
Balance assertion on the same account, a Transaction
with flag = 'P' is added to the view carrying the
postings needed to make the balance match. A multi-currency
pad produces one synth transaction per currency.
Original Pad directives are preserved in the view.
Synth transactions are added alongside, not in place of.
This matters for two reasons:
- BQL queries against the
#entriestable (SELECT * FROM #entries WHERE type = 'pad') can still enumerate the pad directives the user authored. A REPLACE-style expansion would silently zero those out. (BQL’s default SELECT path operates on postings; pads have no postings, so a default SELECT never matches them regardless of this view shape.) - Multi-pad cases (issue #1300) produce exactly one synth
per pad-balance pair:
rustledger_booking::process_pads(whichmerge_with_paddingdelegates to) only retains the most recent same-account pad in its pending-pads map, so earlier same-account pads are silently shadowed and theirsource_accountdoes NOT contribute to the synth. The validator emitsE2003for shadowed pads independently; this view reflects only the effective pad.
Inventory-walking consumers iterate Directive::Transaction
and ignore Pad directives, so the preserved Pads are
invisible to them.
When to use this vs. Ledger.directives:
any consumer that maintains running per-account inventory
state and asks “what is the balance” needs this view. Any
consumer that asks “what did the user write” wants the raw
directives field.
§Performance
Each call clones every source directive once (O(n)).
Inlines the merge logic from
rustledger_booking::merge_with_padding so the already-
owned booked vector can be moved into the merged output
instead of cloned a second time. For short-lived CLI
invocations the single clone is negligible. Long-lived
processes (FFI servers, LSPs) that query the same ledger
repeatedly should hoist the result above their loop.
TODO(perf): memoize internally once a benchmark shows it
matters.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Ledger
impl RefUnwindSafe for Ledger
impl Send for Ledger
impl Sync for Ledger
impl Unpin for Ledger
impl UnsafeUnpin for Ledger
impl UnwindSafe for Ledger
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.