pub struct PriceAnnotationData {
pub is_total: bool,
pub amount: Option<AmountData>,
pub number: Option<String>,
pub currency: Option<String>,
}Expand description
Price annotation data.
Represents price annotations like @ 100 USD or @@ 1000 USD
(total price).
§Type-safe consumption (recommended)
Use PriceAnnotationData::view to get a PriceAnnotationView
— a typed enum that forces consumers to handle Unit and Total
arms exhaustively at compile time. All new code that needs to
distinguish per-unit from total prices MUST use view() rather
than reading is_total directly.
This struct is the wire format (kept for serialization stability
across the WASM plugin boundary). The view() enum is a shaped
accessor on top.
Pre-refactor (issue #992), the implicit_prices plugin read
posting.price.amount directly and silently ignored is_total,
emitting @@ total amounts as per-unit prices. The fix in #997
added explicit handling, but the type system didn’t catch the bug
originally because nothing forced consumers to read the bool. The
view() enum closes that loop: a missing match arm is a compile
error.
Fields§
§is_total: boolWhether this is a total price (@@) vs per-unit (@).
Prefer PriceAnnotationData::view for new code — reading
this field directly is the bug shape that produced #992
(consumer ignores the field and treats every annotation as
per-unit). The view() enum forces exhaustive handling at
compile time.
amount: Option<AmountData>The price amount (optional for incomplete/empty prices).
number: Option<String>The number only (for incomplete prices).
currency: Option<String>The currency only (for incomplete prices).
Implementations§
Source§impl PriceAnnotationData
impl PriceAnnotationData
Sourcepub fn view(&self) -> PriceAnnotationView<'_>
pub fn view(&self) -> PriceAnnotationView<'_>
Get a typed view that distinguishes per-unit from total at
the type level. Use this for new code that needs to handle
the price differently based on @ vs @@.
Returns one of four variants — a missing match arm at the consumer becomes a compile error, eliminating the class of bug that produced issue #992.
Trait Implementations§
Source§impl Clone for PriceAnnotationData
impl Clone for PriceAnnotationData
Source§fn clone(&self) -> PriceAnnotationData
fn clone(&self) -> PriceAnnotationData
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more