Struct fixed_decimal::CompactDecimal
source · pub struct CompactDecimal { /* private fields */ }
Expand description
A struct containing a FixedDecimal
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: FixedDecimal,
exponent: u8,
) -> Self
pub fn from_significand_and_exponent( significand: FixedDecimal, exponent: u8, ) -> Self
Constructs a CompactDecimal
from its significand and exponent.
sourcepub fn significand(&self) -> &FixedDecimal
pub fn significand(&self) -> &FixedDecimal
Returns a reference to the significand of self
.
assert_eq!(
CompactDecimal::from_str("+1.20c6").unwrap().significand(),
&FixedDecimal::from_str("+1.20").unwrap()
);
sourcepub fn into_significand(self) -> FixedDecimal
pub fn into_significand(self) -> FixedDecimal
Returns the significand of self
.
assert_eq!(
CompactDecimal::from_str("+1.20c6")
.unwrap()
.into_significand(),
FixedDecimal::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
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
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
§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.§fn write_to_string(&self) -> Cow<'_, str>
fn write_to_string(&self) -> Cow<'_, str>
String
with the data from this Writeable
. Like ToString
,
but smaller and faster. Read moreimpl 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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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