pub enum CostNumberData {
PerUnit {
value: String,
},
Total {
value: String,
},
PerUnitFromTotal {
per_unit: String,
total: String,
},
}Expand description
The numeric component of a CostData.
Mirrors the host’s rustledger_core::CostNumber on the wire. The
per-unit vs total axes are mutually exclusive by construction —
pre-#1164 they were split into independent number_per /
number_total Option fields on CostData, which allowed the
invalid both-set state on the wire and forced every plugin to write
“what if both?” defensive branches. Numbers are stringly-typed for
arbitrary precision across the WASM boundary.
PerUnitFromTotal is the post-booking shape that plugins see after
the booker has derived a per-unit value from a {{ total }} spec.
It carries BOTH the derived per-unit AND the original total so
plugins that care about precision (e.g. currency_accounts, which
matches Python’s beancount.core.convert.get_cost) can use the
original total rather than redividing.
Serializes as {"kind": "per_unit", "value": "100"} /
{"kind": "total", "value": "1500"} / {"kind": "per_unit_from_total", "per_unit": "150", "total": "300"} — the
kind-tagged shape is shared with FFI-WASI, WASM, and Python so
every client language sees one wire contract.
Variants§
PerUnit
Per-unit cost: {150.00 USD}.
Total
Total cost for the posting’s units: {{ 1500.00 USD }}.
PerUnitFromTotal
Post-booking derived per-unit with the original total preserved.
per_unit == total / |units| by host construction; preferring
total for cost-basis-style reads avoids the
division-then-multiplication precision loss that hits the
rust_decimal 28-digit ceiling on long ledgers.
Implementations§
Source§impl CostNumberData
impl CostNumberData
Sourcepub fn per_unit(&self) -> Option<&str>
pub fn per_unit(&self) -> Option<&str>
Per-unit value if the variant carries one (Self::PerUnit or
Self::PerUnitFromTotal); None for raw Self::Total.
Sourcepub fn total(&self) -> Option<&str>
pub fn total(&self) -> Option<&str>
Total value if the variant carries one (Self::Total or
Self::PerUnitFromTotal); None for raw Self::PerUnit.
Trait Implementations§
Source§impl Clone for CostNumberData
impl Clone for CostNumberData
Source§fn clone(&self) -> CostNumberData
fn clone(&self) -> CostNumberData
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more