pub struct Decimal { /* private fields */ }Expand description
Fixed-point decimal: the value is mantissa × 10^(−scale). This mirrors SQL
DECIMAL(38, scale) (Postgres/Spark cap precision at 38 digits, which is what
an i128 mantissa holds), and is lossless within that range — unlike Float.
Values are normalized on construction: trailing fractional zeros are dropped
(1.50 and 1.5 are equal), and 0 always has scale 0. Equality and
ordering are therefore by numeric value.
Implementations§
Source§impl Decimal
impl Decimal
Sourcepub fn parse(value: impl AsRef<str>) -> Result<Self>
pub fn parse(value: impl AsRef<str>) -> Result<Self>
Parses a decimal numeral such as 3.14, -0.001, or 42. Rejects empty
input, malformed numerals, and values exceeding 38 significant digits.
Sourcepub fn from_parts(mantissa: i128, scale: u32) -> Self
pub fn from_parts(mantissa: i128, scale: u32) -> Self
Builds a decimal from a raw mantissa and scale (mantissa × 10^−scale).
pub fn mantissa(&self) -> i128
pub fn scale(&self) -> u32
Sourcepub fn to_canonical_string(&self) -> String
pub fn to_canonical_string(&self) -> String
Canonical string form (no superfluous trailing zeros).
pub fn checked_add(&self, other: &Self) -> Option<Self>
pub fn checked_sub(&self, other: &Self) -> Option<Self>
pub fn checked_mul(&self, other: &Self) -> Option<Self>
Trait Implementations§
impl Copy for Decimal
Source§impl<'de> Deserialize<'de> for Decimal
impl<'de> Deserialize<'de> for Decimal
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.