Migrating
What to change when upgrading: 0.16 → 0.17, then 0.15 → 0.16. Breaking releases have no deprecation shims; the CHANGELOG has the full old → new tables.
Breaking releases have no deprecation shims: a removed name is gone, so the compiler lists every affected site. The CHANGELOG has the full old → new tables.
🔗From 0.16
- Take totals out through the scale. Replace
to_decimal()plusrescale(2),normalize()orround_dp(2)withdoc.scale().decimal(amount)?; replace× 100withminor_units. - Round your own values with the crate:
scale.round(x)orRounding::round(x, dp), not a hand-pickedRoundingStrategy. - Multiply amounts with
scale.reduce_ratio(&[a, b], &[c]), notDecimal*followed by a rounding; the VAT of one base isvat.tax(base, scale). - A stored fraction is
Percent::from_fraction(dec!(0.19)). VatGroupandCreditApplicationdo not deserialise. Rebuild the document from its inputs.- Your own decimal fields:
#[serde(with = "billing::decimal_str")].
Compiles, prints differently: Percent displays normalised (19 % for 19.00) and a precision applies to the number ({:.1} is 19.0 %); Price with a precision rounds half away from zero. The string grammar accepts trailing zeros past 28 decimals.
🔗From 0.15
🔗Mechanical steps
BillingDocument→Document, built withDocument::builder(currency, scale).- Tax layers → VAT attributes. Put a
Vaton each line and adjustment, or usedefault_vat. A per-unit levy is a line (per_unit_levy). - Every percentage is a
Percent.FixedRateTax::new("VAT", dec!(0.19))becomesVat::standard(Percent::new(dec!(19))); a bareDecimaldoes not compile. - Drop
validate()and friends. Their checks run insidebuild(), which returns a locatedError(BillingErrorandParseAmountErrorare bothError). - Move the header to
en16931: invoice numbers, dates, parties, BT-3 type codes and the BT-20 payment terms text. - Replace the helpers:
| 0.15 | 0.16 |
|---|---|
LineItem::for_usage(..), LineItem::fixed | Line::new(d, Quantity::new(q, "KWH"), UnitPrice::new(Price::new(p))), Line::fixed |
RateSchedule, DynamicPricing, TimeOfUsePricing | Tariff, rate_series, rate_by_key (Pricing) |
*Aggregator | Aggregation (Metering) |
distribute, allocate, prorate | split, split_matrix, Line::segments, Document::split |
minimum_charge*, maximum_charge* | Bound::minimum / Bound::maximum |
with_prepaid, with_advances | .payment(Payment::Gross { .. }), .payment(Payment::Advance(..)) |
merge_period_documents, reverse(meta) | Document::concat, negated() |
🔗Changes that compile and give different values
- Every leaf rounds once at the document’s scale, not via five decimals first; a half-unit amount can move by one cent, towards what a validator recomputes.
- VAT is rounded once per group, and document allowances lower their group’s base (
BR-CO-17), so BT-110 can differ from a tax-layer result, and is correct. - Skonto and interest round at the document’s scale.
Roundinghas no floor or ceiling; a credit rounds like the mirrored debit.negatedis notreverse: it negates amounts and writes no header.Amount::parse("1,000")is refused, and{:.2}of anAmounthonours the precision.Quantity::new’s second argument is the BT-130 unit code ("KWH", not"kWh").Tiers::newrefuses unsorted tiers instead of sorting them.- Payments may exceed the supply: BT-115 goes negative instead of being refused.