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.

On this page

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() plus rescale(2), normalize() or round_dp(2) with doc.scale().decimal(amount)?; replace × 100 with minor_units.
  • Round your own values with the crate: scale.round(x) or Rounding::round(x, dp), not a hand-picked RoundingStrategy.
  • Multiply amounts with scale.reduce_ratio(&[a, b], &[c]), not Decimal * followed by a rounding; the VAT of one base is vat.tax(base, scale).
  • A stored fraction is Percent::from_fraction(dec!(0.19)).
  • VatGroup and CreditApplication do 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

  1. BillingDocument → Document, built with Document::builder(currency, scale).
  2. Tax layers → VAT attributes. Put a Vat on each line and adjustment, or use default_vat. A per-unit levy is a line (per_unit_levy).
  3. Every percentage is a Percent. FixedRateTax::new("VAT", dec!(0.19)) becomes Vat::standard(Percent::new(dec!(19))); a bare Decimal does not compile.
  4. Drop validate() and friends. Their checks run inside build(), which returns a located Error (BillingError and ParseAmountError are both Error).
  5. Move the header to en16931: invoice numbers, dates, parties, BT-3 type codes and the BT-20 payment terms text.
  6. Replace the helpers:
0.150.16
LineItem::for_usage(..), LineItem::fixedLine::new(d, Quantity::new(q, "KWH"), UnitPrice::new(Price::new(p))), Line::fixed
RateSchedule, DynamicPricing, TimeOfUsePricingTariff, rate_series, rate_by_key (Pricing)
*AggregatorAggregation (Metering)
distribute, allocate, proratesplit, 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.
  • Rounding has no floor or ceiling; a credit rounds like the mirrored debit.
  • negated is not reverse: it negates amounts and writes no header.
  • Amount::parse("1,000") is refused, and {:.2} of an Amount honours the precision.
  • Quantity::new’s second argument is the BT-130 unit code ("KWH", not "kWh").
  • Tiers::new refuses unsorted tiers instead of sorting them.
  • Payments may exceed the supply: BT-115 goes negative instead of being refused.

Improve this page on GitHub