pub struct Decimal { /* private fields */ }Expand description
A checked fixed-scale decimal value.
Implementations§
Source§impl Decimal
impl Decimal
Sourcepub const fn new(
spec: DecimalSpec,
coefficient: i128,
) -> Result<Self, DecimalError>
pub const fn new( spec: DecimalSpec, coefficient: i128, ) -> Result<Self, DecimalError>
Validates and creates a decimal from its type and coefficient.
Sourcepub const fn spec(self) -> DecimalSpec
pub const fn spec(self) -> DecimalSpec
Returns the declared decimal type.
Sourcepub const fn coefficient(self) -> i128
pub const fn coefficient(self) -> i128
Returns the signed fixed-scale coefficient.
Sourcepub fn checked_add(self, other: Self) -> Result<Self, DecimalError>
pub fn checked_add(self, other: Self) -> Result<Self, DecimalError>
Adds two values of exactly the same decimal type.
Sourcepub fn checked_sub(self, other: Self) -> Result<Self, DecimalError>
pub fn checked_sub(self, other: Self) -> Result<Self, DecimalError>
Subtracts two values of exactly the same decimal type.
Sourcepub fn checked_cmp(self, other: Self) -> Result<Ordering, DecimalError>
pub fn checked_cmp(self, other: Self) -> Result<Ordering, DecimalError>
Compares two values of exactly the same decimal type.
Sourcepub fn rescale(self, target: DecimalSpec) -> Result<Self, DecimalError>
pub fn rescale(self, target: DecimalSpec) -> Result<Self, DecimalError>
Changes the declared scale without rounding or changing the numeric value.
Trait Implementations§
impl Copy for Decimal
impl Eq for Decimal
Source§impl PartialOrd for Decimal
impl PartialOrd for Decimal
impl StructuralPartialEq for Decimal
Auto Trait Implementations§
impl Freeze for Decimal
impl RefUnwindSafe for Decimal
impl Send for Decimal
impl Sync for Decimal
impl Unpin for Decimal
impl UnsafeUnpin for Decimal
impl UnwindSafe for Decimal
Blanket Implementations§
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
Mutably borrows from an owned value. Read more