pub trait DynDecimal: 'static {
Show 25 methods
// Required methods
fn width(&self) -> DecimalWidth;
fn scale_dyn(&self) -> u32;
fn max_scale(&self) -> u32;
fn raw_storage(&self) -> RawStorage;
fn as_any(&self) -> &dyn Any;
fn clone_box(&self) -> Box<dyn DynDecimal>;
fn is_zero(&self) -> bool;
fn is_one(&self) -> bool;
fn is_positive(&self) -> bool;
fn is_negative(&self) -> bool;
fn signum(&self) -> Box<dyn DynDecimal>;
fn abs(&self) -> Box<dyn DynDecimal>;
fn neg(&self) -> Box<dyn DynDecimal>;
fn add(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>;
fn sub(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>;
fn mul(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>;
fn div(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>;
fn rem(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>;
fn rescale_to(&self, target_scale: u32) -> Option<Box<dyn DynDecimal>>;
fn rescale_to_with(
&self,
target_scale: u32,
mode: RoundingMode,
) -> Option<Box<dyn DynDecimal>>;
fn eq_dyn(&self, rhs: &dyn DynDecimal) -> bool;
fn cmp_dyn(&self, rhs: &dyn DynDecimal) -> Option<Ordering>;
fn display(&self) -> String;
fn to_f64(&self) -> f64;
fn to_int(&self) -> i64;
}Expand description
Object-safe, width-erased view of a decimal value.
Implemented by every concrete Dxx<S> shipped with the crate. See
the module-level documentation for the cross-width / cross-scale
semantics and the cost model.
The trait is intentionally narrower than crate::Decimal: it
covers identity, sign, comparison, arithmetic, rescale, the float
bridge, and Display. Transcendental functions and constants live
only on the typed surface — use DynDecimal::as_any to downcast
to a concrete Dxx<S> and call them there.
Required Methods§
Sourcefn width(&self) -> DecimalWidth
fn width(&self) -> DecimalWidth
Returns the storage tier this value lives in.
Sourcefn raw_storage(&self) -> RawStorage
fn raw_storage(&self) -> RawStorage
Returns the raw storage integer (scale stripped).
Sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Returns this value as a &dyn Any for downcasting to a
concrete Dxx<S>.
Sourcefn clone_box(&self) -> Box<dyn DynDecimal>
fn clone_box(&self) -> Box<dyn DynDecimal>
Heap-clones into a fresh Box<dyn DynDecimal>.
Sourcefn is_one(&self) -> bool
fn is_one(&self) -> bool
Returns true if this value is the multiplicative identity for its type.
Sourcefn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Returns true if self > 0.
Sourcefn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Returns true if self < 0.
Sourcefn signum(&self) -> Box<dyn DynDecimal>
fn signum(&self) -> Box<dyn DynDecimal>
Returns +1, 0, or -1 (each at the same width/scale as self).
Sourcefn abs(&self) -> Box<dyn DynDecimal>
fn abs(&self) -> Box<dyn DynDecimal>
Returns |self|.
Sourcefn neg(&self) -> Box<dyn DynDecimal>
fn neg(&self) -> Box<dyn DynDecimal>
Returns -self.
Sourcefn add(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>
fn add(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>
self + rhs. Returns None if widths differ, if the auto-rescale
to the wider scale overflows, or if the sum overflows.
Sourcefn sub(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>
fn sub(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>
self - rhs. Same width / overflow contract as Self::add.
Sourcefn mul(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>
fn mul(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>
self * rhs. Same width / overflow contract as Self::add.
Sourcefn div(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>
fn div(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>
self / rhs. Returns None on width mismatch, rescale overflow,
product overflow, or division by zero.
Sourcefn rem(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>
fn rem(&self, rhs: &dyn DynDecimal) -> Option<Box<dyn DynDecimal>>
self % rhs. Same contract as Self::div.
Sourcefn rescale_to(&self, target_scale: u32) -> Option<Box<dyn DynDecimal>>
fn rescale_to(&self, target_scale: u32) -> Option<Box<dyn DynDecimal>>
Rescale to target_scale using the crate-default rounding mode.
Returns None if target_scale > max_scale() or the scale-up
multiplication overflows.
Sourcefn rescale_to_with(
&self,
target_scale: u32,
mode: RoundingMode,
) -> Option<Box<dyn DynDecimal>>
fn rescale_to_with( &self, target_scale: u32, mode: RoundingMode, ) -> Option<Box<dyn DynDecimal>>
Rescale with an explicit rounding mode. See Self::rescale_to.
Sourcefn eq_dyn(&self, rhs: &dyn DynDecimal) -> bool
fn eq_dyn(&self, rhs: &dyn DynDecimal) -> bool
Equality after width check + lossless rescale to the wider scale. Different widths are never equal.
Sourcefn cmp_dyn(&self, rhs: &dyn DynDecimal) -> Option<Ordering>
fn cmp_dyn(&self, rhs: &dyn DynDecimal) -> Option<Ordering>
Ordering after width check + lossless rescale to the wider scale.
Different widths return None.
Sourcefn to_int(&self) -> i64
fn to_int(&self) -> i64
Conversion to i64 using the crate-default rounding mode.
Saturates on overflow; see crate::DecimalConvert::to_int.