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 moreSource§impl Debug for CostNumberData
impl Debug for CostNumberData
Source§impl<'de> Deserialize<'de> for CostNumberData
impl<'de> Deserialize<'de> for CostNumberData
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CostNumberData, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CostNumberData, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for CostNumberData
impl Serialize for CostNumberData
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for CostNumberData
impl RefUnwindSafe for CostNumberData
impl Send for CostNumberData
impl Sync for CostNumberData
impl Unpin for CostNumberData
impl UnsafeUnpin for CostNumberData
impl UnwindSafe for CostNumberData
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.