pub struct CompactDecimal { /* private fields */ }Expand description
A struct containing a Decimal significand together with an exponent, representing a
number written in compact notation (such as 1.2M).
This represents a source number, as defined
in UTS #35.
The value exponent=0 represents a number in non-compact
notation (such as 1 200 000).
This is distinct from crate::ScientificDecimal because it does not represent leading 0s
nor a sign in the exponent, and behaves differently in pluralization.
Implementations§
Source§impl CompactDecimal
 
impl CompactDecimal
Sourcepub fn from_significand_and_exponent(significand: Decimal, exponent: u8) -> Self
 
pub fn from_significand_and_exponent(significand: Decimal, exponent: u8) -> Self
Constructs a CompactDecimal from its significand and exponent.
Sourcepub fn significand(&self) -> &Decimal
 
pub fn significand(&self) -> &Decimal
Returns a reference to the significand of self.
assert_eq!(
    CompactDecimal::from_str("+1.20c6").unwrap().significand(),
    &Decimal::from_str("+1.20").unwrap()
);Sourcepub fn into_significand(self) -> Decimal
 
pub fn into_significand(self) -> Decimal
Returns the significand of self.
assert_eq!(
    CompactDecimal::from_str("+1.20c6")
        .unwrap()
        .into_significand(),
    Decimal::from_str("+1.20").unwrap()
);Source§impl CompactDecimal
 
impl CompactDecimal
Sourcepub fn try_from_str(s: &str) -> Result<Self, ParseError>
 
pub fn try_from_str(s: &str) -> Result<Self, ParseError>
Parses a CompactDecimal.
Trait Implementations§
Source§impl Clone for CompactDecimal
 
impl Clone for CompactDecimal
Source§fn clone(&self) -> CompactDecimal
 
fn clone(&self) -> CompactDecimal
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
 
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompactDecimal
 
impl Debug for CompactDecimal
Source§impl Display for CompactDecimal
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
 
impl Display for CompactDecimal
This trait is implemented for compatibility with fmt!.
To create a string, [Writeable::write_to_string] is usually more efficient.
Source§impl FromStr for CompactDecimal
 
impl FromStr for CompactDecimal
Source§impl PartialEq for CompactDecimal
 
impl PartialEq for CompactDecimal
Source§impl Writeable for CompactDecimal
Render the CompactDecimal in sampleValue syntax.
The letter c is used, rather than the deprecated e.
 
impl Writeable for CompactDecimal
Render the CompactDecimal in sampleValue syntax.
The letter c is used, rather than the deprecated e.
§Examples
assert_writeable_eq!(
    CompactDecimal::from_str("+1.20c6").unwrap(),
    "+1.20c6"
);
assert_writeable_eq!(CompactDecimal::from_str("+1729").unwrap(), "+1729");Source§fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
 
fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result
write_to_parts, and discards any
Part annotations.Source§fn writeable_length_hint(&self) -> LengthHint
 
fn writeable_length_hint(&self) -> LengthHint
Source§fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error>where
    S: PartsWrite + ?Sized,
 
fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error>where
    S: PartsWrite + ?Sized,
Part annotations to the given sink. Errors from the
sink are bubbled up. The default implementation delegates to write_to,
and doesn’t produce any Part annotations.impl StructuralPartialEq for CompactDecimal
Auto Trait Implementations§
impl Freeze for CompactDecimal
impl RefUnwindSafe for CompactDecimal
impl Send for CompactDecimal
impl Sync for CompactDecimal
impl Unpin for CompactDecimal
impl UnwindSafe for CompactDecimal
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
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more