pub struct BookedCostInvariantError {
pub per_unit: Decimal,
pub total: Decimal,
pub units: Decimal,
pub derived_total: Decimal,
pub abs_diff: Decimal,
pub tolerance: Option<Decimal>,
pub overflow: bool,
}Expand description
Diagnostic for a failed BookedCost consistency check.
Returned by BookedCost::try_new in three cases:
- Mismatch:
per_unit * |units|doesn’t agree withtotalto within therust_decimalrounding floor. - Zero units: every
per_unit“works” by zero-multiplication so the invariant carries no information; the post-booking shape is structurally meaningless without units. - Overflow:
per_unit * |units|would exceedDecimal::MAX(~7.92e28). Both operands fit inDecimalindividually but their product doesn’t. A wire client can reach this with extreme inputs; surfacing it as a typed error keeps the host from panicking on multiplication.
Carries the inputs and (for the mismatch case) the computed
residual so trust-boundary callers can surface a meaningful error
to the originating plugin or wire client (“you sent
per_unit=50, total=999 with units=10; derived total would be
500, off by 499 — far outside tolerance 1e-20”). Mapping this to a
ConversionError variant gives plugin authors a typed category
for the failure instead of conflating with InvalidNumber (parse
failure).
Fields§
§per_unit: DecimalThe per-unit value the caller supplied.
total: DecimalThe total value the caller supplied.
units: DecimalThe units value the caller supplied (caller-side sign retained so error messages can show what came in).
derived_total: Decimalper_unit * |units|, the value we’d expect total to equal.
Decimal::ZERO when the multiplication couldn’t be performed
(zero units, or overflow — see Self::overflow).
abs_diff: Decimal|derived_total - total|, the magnitude of the violation.
Decimal::ZERO for the zero-units and overflow cases.
tolerance: Option<Decimal>The tolerance threshold we tested against. None when units
was zero or the multiplication overflowed — see
Self::overflow to distinguish the two.
overflow: booltrue when per_unit * |units| overflowed Decimal::MAX
(~7.92e28). Distinguishes the overflow case from the zero-units
case, since both leave tolerance: None.
Trait Implementations§
Source§impl Clone for BookedCostInvariantError
impl Clone for BookedCostInvariantError
Source§fn clone(&self) -> BookedCostInvariantError
fn clone(&self) -> BookedCostInvariantError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for BookedCostInvariantError
Source§impl Debug for BookedCostInvariantError
impl Debug for BookedCostInvariantError
Source§impl Display for BookedCostInvariantError
impl Display for BookedCostInvariantError
impl Eq for BookedCostInvariantError
Source§impl Error for BookedCostInvariantError
impl Error for BookedCostInvariantError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl PartialEq for BookedCostInvariantError
impl PartialEq for BookedCostInvariantError
Source§fn eq(&self, other: &BookedCostInvariantError) -> bool
fn eq(&self, other: &BookedCostInvariantError) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for BookedCostInvariantError
Auto Trait Implementations§
impl Freeze for BookedCostInvariantError
impl RefUnwindSafe for BookedCostInvariantError
impl Send for BookedCostInvariantError
impl Sync for BookedCostInvariantError
impl Unpin for BookedCostInvariantError
impl UnsafeUnpin for BookedCostInvariantError
impl UnwindSafe for BookedCostInvariantError
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§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.