pub struct Decimal { /* private fields */ }Expand description
An exact decimal number units · 10^−scale – a price per unit, a quantity, a rate. Money is crate::Money.
A value has one form only: the smallest scale (units not divisible by ten unless the scale is 0), written as
a string in exactly one way ("1.5", never "1.50"; "0", never "-0"). Reading rejects any other form, so
the same value always has the same bytes and the same hash. Addition and subtraction are exact; rounding is a
rule of the law that applies, not of the protocol.
Implementations§
Source§impl Decimal
impl Decimal
Sourcepub fn new(units: i128, scale: u8) -> Option<Self>
pub fn new(units: i128, scale: u8) -> Option<Self>
units · 10^−scale, reduced to its one form; None if the scale is above Self::MAX_SCALE.
Sourcepub fn is_negative(self) -> bool
pub fn is_negative(self) -> bool
Whether the value is below zero.
Sourcepub fn checked_add(self, other: Self) -> Option<Self>
pub fn checked_add(self, other: Self) -> Option<Self>
The exact sum, or None on overflow.
Sourcepub fn checked_sub(self, other: Self) -> Option<Self>
pub fn checked_sub(self, other: Self) -> Option<Self>
The exact difference, or None on overflow.
Trait Implementations§
impl Copy for Decimal
Source§impl<'de> Deserialize<'de> for Decimal
impl<'de> Deserialize<'de> for Decimal
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Decimal
Source§impl Ord for Decimal
impl Ord for Decimal
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
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