Struct fixed_decimal::UnsignedFixedDecimal

source ·
pub struct UnsignedFixedDecimal { /* private fields */ }
Expand description

A struct containing decimal digits with efficient iteration and manipulation by magnitude (power of 10).

Supports a mantissa of non-zero digits and a number of leading and trailing zeros; used for formatting and plural selection.

§Data Types

The following types can be converted to a UnsignedFixedDecimal:

  • Integers, unsigned
  • Strings representing an arbitrary-precision decimal
  • Floating point values (using the ryu feature)

To create a UnsignedFixedDecimal with fraction digits, either create it from an integer and then call UnsignedFixedDecimal::multiplied_pow10, create it from a string, or (when the ryu feature is enabled) create it from a floating point value using UnsignedFixedDecimal::try_from_f64.

§Magnitude and Position

Each digit in a FixedDecimal is indexed by a magnitude, or the digit’s power of 10. Illustration for the number “12.34”:

MagnitudeDigitDescription
11Tens place
02Ones place
-13Tenths place
-24Hundredths place

Some functions deal with a position for the purpose of padding, truncating, or rounding a number. In these cases, the position sits between the corresponding magnitude of that position and the next lower significant digit. Illustration:

Position:   2   0  -2
Number:     |1|2.3|4|
Position:     1  -1

Expected output of various operations, all with input “12.34”:

OperationPositionExpected Result
Truncate to tens110
Truncate to tenths-112.3
Pad to ten thousands40012.34
Pad to ten thousandths-412.3400

§Examples

use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from(250u32);
assert_eq!("250", dec.to_string());

dec.multiply_pow10(-2);
assert_eq!("2.50", dec.to_string());

Implementations§

source§

impl UnsignedFixedDecimal

source

pub fn digit_at(&self, magnitude: i16) -> u8

Gets the digit at the specified order of magnitude. Returns 0 if the magnitude is out of range of the currently visible digits.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec = UnsignedFixedDecimal::from(945u32);
assert_eq!(0, dec.digit_at(-1));
assert_eq!(5, dec.digit_at(0));
assert_eq!(4, dec.digit_at(1));
assert_eq!(9, dec.digit_at(2));
assert_eq!(0, dec.digit_at(3));
source

pub const fn magnitude_range(&self) -> RangeInclusive<i16>

Gets the visible range of digit magnitudes, in ascending order of magnitude. Call .rev() on the return value to get the range in descending order. Magnitude 0 is always included, even if the number has leading or trailing zeros.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec: UnsignedFixedDecimal = "012.340".parse().expect("valid syntax");
assert_eq!(-3..=2, dec.magnitude_range());
source

pub fn nonzero_magnitude_start(&self) -> i16

Gets the magnitude of the largest nonzero digit. If the number is zero, 0 is returned.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec: UnsignedFixedDecimal = "012.340".parse().expect("valid syntax");
assert_eq!(1, dec.nonzero_magnitude_start());

assert_eq!(0, UnsignedFixedDecimal::from(0u32).nonzero_magnitude_start());
source

pub fn nonzero_magnitude_end(&self) -> i16

Gets the magnitude of the smallest nonzero digit. If the number is zero, 0 is returned.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec: UnsignedFixedDecimal = "012.340".parse().expect("valid syntax");
assert_eq!(-2, dec.nonzero_magnitude_end());

assert_eq!(0, UnsignedFixedDecimal::from(0u32).nonzero_magnitude_end());
source

pub fn is_zero(&self) -> bool

Returns whether the number has a numeric value of zero.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec: UnsignedFixedDecimal = "000.000".parse().expect("valid syntax");
assert!(dec.is_zero());
source

pub fn multiply_pow10(&mut self, delta: i16)

Shift the digits of this number by a power of 10.

Leading or trailing zeros may be added to keep the digit at magnitude 0 (the last digit before the decimal separator) visible.

NOTE: if the operation causes overflow, the number will be set to zero.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from(42u32);
assert_eq!("42", dec.to_string());

dec.multiply_pow10(3);
assert_eq!("42000", dec.to_string());
source

pub fn multiplied_pow10(self, delta: i16) -> Self

Returns this number with its digits shifted by a power of 10.

Leading or trailing zeros may be added to keep the digit at magnitude 0 (the last digit before the decimal separator) visible.

NOTE: if the operation causes overflow, the returned number will be zero.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec = UnsignedFixedDecimal::from(42u32).multiplied_pow10(3);
assert_eq!("42000", dec.to_string());
source

pub fn trimmed_start(self) -> Self

Returns this number with its leading zeroes removed.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec = UnsignedFixedDecimal::from(123400u32)
    .multiplied_pow10(-4)
    .padded_start(4);
assert_eq!("0012.3400", dec.to_string());

assert_eq!("12.3400", dec.trimmed_start().to_string());
source

pub fn trim_start(&mut self)

Removes the leading zeroes of this number.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from(123400u32)
    .multiplied_pow10(-4)
    .padded_start(4);
assert_eq!("0012.3400", dec.to_string());

dec.trim_start();
assert_eq!("12.3400", dec.to_string());

There is no effect if the most significant digit has magnitude less than zero

let mut dec = UnsignedFixedDecimal::from(22u32).multiplied_pow10(-4);
assert_eq!("0.0022", dec.to_string());

dec.trim_start();
assert_eq!("0.0022", dec.to_string());
source

pub fn trimmed_end(self) -> Self

Returns this number with its trailing zeros removed.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec = UnsignedFixedDecimal::from(123400u32)
    .multiplied_pow10(-4)
    .padded_start(4);
assert_eq!("0012.3400", dec.to_string());

assert_eq!("0012.34", dec.trimmed_end().to_string());
source

pub fn trim_end(&mut self)

Removes the trailing zeros of this number.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from(123400u32)
    .multiplied_pow10(-4)
    .padded_start(4);
assert_eq!("0012.3400", dec.to_string());

dec.trim_end();
assert_eq!("0012.34", dec.to_string());

There is no effect if the least significant digit has magnitude more than zero:

let mut dec = UnsignedFixedDecimal::from(2200u32);
assert_eq!("2200", dec.to_string());

dec.trim_end();
assert_eq!("2200", dec.to_string());
source

pub fn trimmed_end_if_integer(self) -> Self

Returns this number with its trailing zeros removed, but only if the number is an integer

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec = UnsignedFixedDecimal::from(12340000u32)
    .multiplied_pow10(-2);
assert_eq!("123400.00", dec.to_string());
assert_eq!("123400", dec.trimmed_end_if_integer().to_string());

// No effect if there are nonzero fractional digits:
let dec = UnsignedFixedDecimal::from(123400u32)
    .multiplied_pow10(-4)
    .padded_start(4);
assert_eq!("0012.3400", dec.to_string());
assert_eq!("0012.3400", dec.trimmed_end_if_integer().to_string());
source

pub fn trim_end_if_integer(&mut self)

Removes the trailing zeros of this number, but only if the number is an integer

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from(12340000u32)
    .multiplied_pow10(-2);
assert_eq!("123400.00", dec.to_string());

dec.trim_end_if_integer();
assert_eq!("123400", dec.to_string());

// No effect on trailing zeros in the integer:
dec.trim_end_if_integer();
assert_eq!("123400", dec.to_string());

// No effect if there are nonzero fractional digits:
dec.multiply_pow10(-4);
dec.pad_start(4);
assert_eq!("0012.3400", dec.to_string());

dec.trim_end_if_integer();
assert_eq!("0012.3400", dec.to_string());
source

pub fn padded_start(self, position: i16) -> Self

Returns this number padded with leading zeros on a particular position.

Negative position numbers have no effect.

Also see UnsignedFixedDecimal::with_max_position().

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from(42u32);
assert_eq!("42", dec.to_string());
assert_eq!("0042", dec.clone().padded_start(4).to_string());

assert_eq!("042", dec.clone().padded_start(3).to_string());

assert_eq!("42", dec.clone().padded_start(2).to_string());

assert_eq!("42", dec.clone().padded_start(1).to_string());
source

pub fn pad_start(&mut self, position: i16)

Pads this number with leading zeros on a particular position.

Negative position numbers have no effect.

Also see UnsignedFixedDecimal::set_max_position().

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from(42u32);
assert_eq!("42", dec.to_string());

dec.pad_start(4);
assert_eq!("0042", dec.to_string());

dec.pad_start(3);
assert_eq!("042", dec.to_string());

dec.pad_start(2);
assert_eq!("42", dec.to_string());

dec.pad_start(1);
assert_eq!("42", dec.to_string());
source

pub fn padded_end(self, position: i16) -> Self

Returns this number padded with trailing zeros on a particular (negative) position. Will truncate zeros if necessary, but will not truncate other digits.

Positive position numbers have no effect.

Also see UnsignedFixedDecimal::trunced().

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from_str("123.456").unwrap();
assert_eq!("123.456", dec.to_string());

assert_eq!("123.456", dec.clone().padded_end(-1).to_string());

assert_eq!("123.456", dec.clone().padded_end(-2).to_string());

assert_eq!("123.456000", dec.clone().padded_end(-6).to_string());

assert_eq!("123.4560", dec.clone().padded_end(-4).to_string());
source

pub fn pad_end(&mut self, position: i16)

Pads this number with trailing zeros on a particular (non-positive) position. Will truncate trailing zeros if necessary, but will not truncate other digits.

Positive position numbers have no effect.

Also see UnsignedFixedDecimal::trunc().

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from_str("123.456").unwrap();
assert_eq!("123.456", dec.to_string());

dec.pad_end(-2);
assert_eq!("123.456", dec.to_string());

dec.pad_end(-6);
assert_eq!("123.456000", dec.to_string());

let mut dec = UnsignedFixedDecimal::from_str("123.000").unwrap();
dec.pad_end(0);
assert_eq!("123", dec.to_string());
source

pub fn with_max_position(self, position: i16) -> Self

Returns this number with the leading significant digits truncated to a particular position, deleting digits if necessary.

Also see UnsignedFixedDecimal::padded_start().

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from(4235970u32).multiplied_pow10(-3);
assert_eq!("4235.970", dec.to_string());

assert_eq!("04235.970", dec.clone().with_max_position(5).to_string());

assert_eq!("35.970", dec.clone().with_max_position(2).to_string());

assert_eq!("5.970", dec.clone().with_max_position(1).to_string());

assert_eq!("0.970", dec.clone().with_max_position(0).to_string());

assert_eq!("0.070", dec.clone().with_max_position(-1).to_string());

assert_eq!("0.000", dec.clone().with_max_position(-2).to_string());

assert_eq!("0.0000", dec.clone().with_max_position(-4).to_string());
source

pub fn set_max_position(&mut self, position: i16)

Truncates the leading significant digits of this number to a particular position, deleting digits if necessary.

Also see UnsignedFixedDecimal::pad_start().

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from(4235970u32).multiplied_pow10(-3);
assert_eq!("4235.970", dec.to_string());

dec.set_max_position(5);
assert_eq!("04235.970", dec.to_string());

dec.set_max_position(2);
assert_eq!("35.970", dec.to_string());

dec.set_max_position(1);
assert_eq!("5.970", dec.to_string());

dec.set_max_position(0);
assert_eq!("0.970", dec.to_string());

dec.set_max_position(-1);
assert_eq!("0.070", dec.to_string());

dec.set_max_position(-2);
assert_eq!("0.000", dec.to_string());

dec.set_max_position(-4);
assert_eq!("0.0000", dec.to_string());
source

pub fn round(&mut self, position: i16)

Rounds this number at a particular digit position.

This uses half to even rounding, which rounds to the nearest integer and resolves ties by selecting the nearest even integer to the original value.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from_str("0.4").unwrap();
dec.round(0);
assert_eq!("0", dec.to_string());
let mut dec = UnsignedFixedDecimal::from_str("0.5").unwrap();
dec.round(0);
assert_eq!("0", dec.to_string());
let mut dec = UnsignedFixedDecimal::from_str("0.6").unwrap();
dec.round(0);
assert_eq!("1", dec.to_string());
let mut dec = UnsignedFixedDecimal::from_str("1.5").unwrap();
dec.round(0);
assert_eq!("2", dec.to_string());
source

pub fn rounded(self, position: i16) -> Self

Returns this number rounded at a particular digit position.

This uses half to even rounding by default, which rounds to the nearest integer and resolves ties by selecting the nearest even integer to the original value.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from_str("0.4").unwrap();
assert_eq!("0", dec.rounded(0).to_string());
let mut dec = UnsignedFixedDecimal::from_str("0.5").unwrap();
assert_eq!("0", dec.rounded(0).to_string());
let mut dec = UnsignedFixedDecimal::from_str("0.6").unwrap();
assert_eq!("1", dec.rounded(0).to_string());
let mut dec = UnsignedFixedDecimal::from_str("1.5").unwrap();
assert_eq!("2", dec.rounded(0).to_string());
source

pub fn expand(&mut self, position: i16)

Rounds this number away from zero at a particular digit position.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from_str("0.4").unwrap();
dec.expand(0);
assert_eq!("1", dec.to_string());
let mut dec = UnsignedFixedDecimal::from_str("0.5").unwrap();
dec.expand(0);
assert_eq!("1", dec.to_string());
let mut dec = UnsignedFixedDecimal::from_str("0.6").unwrap();
dec.expand(0);
assert_eq!("1", dec.to_string());
let mut dec = UnsignedFixedDecimal::from_str("1.5").unwrap();
dec.expand(0);
assert_eq!("2", dec.to_string());
source

pub fn expanded(self, position: i16) -> Self

Returns this number rounded away from zero at a particular digit position.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec = UnsignedFixedDecimal::from_str("0.4").unwrap();
assert_eq!("1", dec.expanded(0).to_string());
let dec = UnsignedFixedDecimal::from_str("0.5").unwrap();
assert_eq!("1", dec.expanded(0).to_string());
let dec = UnsignedFixedDecimal::from_str("0.6").unwrap();
assert_eq!("1", dec.expanded(0).to_string());
let dec = UnsignedFixedDecimal::from_str("1.5").unwrap();
assert_eq!("2", dec.expanded(0).to_string());
source

pub fn trunc(&mut self, position: i16)

Rounds this number towards zero at a particular digit position.

Also see UnsignedFixedDecimal::pad_end().

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut dec = UnsignedFixedDecimal::from_str("0.4").unwrap();
dec.trunc(0);
assert_eq!("0", dec.to_string());
let mut dec = UnsignedFixedDecimal::from_str("0.5").unwrap();
dec.trunc(0);
assert_eq!("0", dec.to_string());
let mut dec = UnsignedFixedDecimal::from_str("0.6").unwrap();
dec.trunc(0);
assert_eq!("0", dec.to_string());
let mut dec = UnsignedFixedDecimal::from_str("1.5").unwrap();
dec.trunc(0);
assert_eq!("1", dec.to_string());
source

pub fn trunced(self, position: i16) -> Self

Returns this number rounded towards zero at a particular digit position.

Also see UnsignedFixedDecimal::padded_end().

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let dec = UnsignedFixedDecimal::from_str("0.4").unwrap();
assert_eq!("0", dec.trunced(0).to_string());
let dec = UnsignedFixedDecimal::from_str("0.5").unwrap();
assert_eq!("0", dec.trunced(0).to_string());
let dec = UnsignedFixedDecimal::from_str("0.6").unwrap();
assert_eq!("0", dec.trunced(0).to_string());
let dec = UnsignedFixedDecimal::from_str("1.5").unwrap();
assert_eq!("1", dec.trunced(0).to_string());
source

pub fn round_with_mode(&mut self, position: i16, mode: UnsignedRoundingMode)

Rounds this number at a particular digit position, using the specified rounding mode.

§Examples
use fixed_decimal::{UnsignedFixedDecimal, UnsignedRoundingMode};

let mut dec = UnsignedFixedDecimal::from_str("5.455").unwrap();
dec.round_with_mode(-2, UnsignedRoundingMode::HalfExpand);
assert_eq!("5.46", dec.to_string());
let mut dec = UnsignedFixedDecimal::from_str("9.75").unwrap();
dec.round_with_mode(-1, UnsignedRoundingMode::HalfEven);
assert_eq!("9.8", dec.to_string());
source

pub fn rounded_with_mode( self, position: i16, mode: UnsignedRoundingMode, ) -> Self

Returns this number rounded at a particular digit position, using the specified rounding mode.

§Examples
use fixed_decimal::{UnsignedFixedDecimal, UnsignedRoundingMode};

let mut dec = UnsignedFixedDecimal::from_str("5.455").unwrap();
assert_eq!(
    "5.46",
    dec.rounded_with_mode(-2, UnsignedRoundingMode::HalfExpand)
        .to_string()
);
let mut dec = UnsignedFixedDecimal::from_str("9.75").unwrap();
assert_eq!(
    "9.8",
    dec.rounded_with_mode(-1, UnsignedRoundingMode::HalfEven)
        .to_string()
);
source

pub fn round_with_mode_and_increment( &mut self, position: i16, mode: UnsignedRoundingMode, increment: RoundingIncrement, )

Rounds this number at a particular digit position and increment, using the specified rounding mode.

§Examples
use fixed_decimal::{UnsignedFixedDecimal, RoundingIncrement, UnsignedRoundingMode};

let mut dec = UnsignedFixedDecimal::from_str("5.455").unwrap();
dec.round_with_mode_and_increment(
    -2,
    UnsignedRoundingMode::HalfExpand,
    RoundingIncrement::MultiplesOf5,
);
assert_eq!("5.45", dec.to_string());

let mut dec = UnsignedFixedDecimal::from_str("9.75").unwrap();
dec.round_with_mode_and_increment(
    -1,
    UnsignedRoundingMode::HalfEven,
    RoundingIncrement::MultiplesOf5,
);
assert_eq!("10.0", dec.to_string());
source

pub fn rounded_with_mode_and_increment( self, position: i16, mode: UnsignedRoundingMode, increment: RoundingIncrement, ) -> Self

Returns this number rounded at a particular digit position and increment, using the specified rounding mode.

§Examples
use fixed_decimal::{UnsignedFixedDecimal, RoundingIncrement, UnsignedRoundingMode};

let mut dec = UnsignedFixedDecimal::from_str("5.455").unwrap();
assert_eq!(
    "5.45",
    dec.rounded_with_mode_and_increment(
        -2,
        UnsignedRoundingMode::HalfExpand,
        RoundingIncrement::MultiplesOf5
    )
    .to_string()
);

let mut dec = UnsignedFixedDecimal::from_str("9.75").unwrap();
assert_eq!(
    "10.0",
    dec.rounded_with_mode_and_increment(
        -1,
        UnsignedRoundingMode::HalfEven,
        RoundingIncrement::MultiplesOf5
    )
    .to_string()
);
source

pub fn concatenated_end( self, other: UnsignedFixedDecimal, ) -> Result<Self, (UnsignedFixedDecimal, UnsignedFixedDecimal)>

Concatenate another UnsignedFixedDecimal into the end of this UnsignedFixedDecimal.

All nonzero digits in other must have lower magnitude than nonzero digits in self. If the two decimals represent overlapping ranges of magnitudes, an Err is returned, containing (self, other).

The magnitude range of self will be increased if other covers a larger range.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let integer = UnsignedFixedDecimal::from(123u32);
let fraction = UnsignedFixedDecimal::from(456u32).multiplied_pow10(-3);

let result = integer.concatenated_end(fraction).expect("nonoverlapping");

assert_eq!("123.456", result.to_string());
source

pub fn concatenate_end( &mut self, other: UnsignedFixedDecimal, ) -> Result<(), UnsignedFixedDecimal>

Concatenate another UnsignedFixedDecimal into the end of this UnsignedFixedDecimal.

All nonzero digits in other must have lower magnitude than nonzero digits in self. If the two decimals represent overlapping ranges of magnitudes, an Err is returned, passing ownership of other back to the caller.

The magnitude range of self will be increased if other covers a larger range.

§Examples
use fixed_decimal::UnsignedFixedDecimal;

let mut integer = UnsignedFixedDecimal::from(123u32);
let fraction = UnsignedFixedDecimal::from(456u32).multiplied_pow10(-3);

integer.concatenate_end(fraction);

assert_eq!("123.456", integer.to_string());
source§

impl UnsignedFixedDecimal

source

pub fn to_string(&self) -> String

Converts the given value to a String.

Under the hood, this uses an efficient [Writeable] implementation. However, in order to avoid allocating a string, it is more efficient to use [Writeable] directly.

source§

impl UnsignedFixedDecimal

source

pub fn try_from_str(s: &str) -> Result<Self, ParseError>

source

pub fn try_from_utf8(input_str: &[u8]) -> Result<Self, ParseError>

This function is used to parse a UnsignedFixedDecimal from a string without a sign.

§Examples
use fixed_decimal::UnsignedFixedDecimal;
use fixed_decimal::ParseError;

let decimal = UnsignedFixedDecimal::try_from_utf8(b"1234567890");
assert_eq!(decimal, Ok(UnsignedFixedDecimal::from(1234567890u32)));

// In case of adding `+`, the function will return an error.
let decimal = UnsignedFixedDecimal::try_from_utf8(b"+1234567890");
assert_eq!(decimal, Err(ParseError::Syntax));

// In case of adding `-`, the function will return error
let decimal = UnsignedFixedDecimal::try_from_utf8(b"-1234567890");
assert_eq!(decimal, Err(ParseError::Syntax));
source§

impl UnsignedFixedDecimal

source

pub fn try_from_f64( float: f64, precision: FloatPrecision, ) -> Result<Self, LimitError>

Constructs a UnsignedFixedDecimal from an f64.

Since f64 values do not carry a notion of their precision, the second argument to this function specifies the type of precision associated with the f64. For more information, see FloatPrecision.

This function uses ryu, which is an efficient double-to-string algorithm, but other implementations may yield higher performance; for more details, see icu4x#166.

This function can be made available with the "ryu" Cargo feature.

NOTE: Negative numbers are not supported.

use fixed_decimal::{UnsignedFixedDecimal, FloatPrecision};
use writeable::assert_writeable_eq;

let decimal =
    UnsignedFixedDecimal::try_from_f64(-5.1, FloatPrecision::Magnitude(-2))
        .expect_err("Negative numbers are not supported");

let decimal =
    UnsignedFixedDecimal::try_from_f64(0.012345678, FloatPrecision::RoundTrip)
        .expect("Finite quantity");
assert_writeable_eq!(decimal, "0.012345678");

let decimal =
    UnsignedFixedDecimal::try_from_f64(12345678000., FloatPrecision::Integer)
        .expect("Finite, integer-valued quantity");
assert_writeable_eq!(decimal, "12345678000");

Trait Implementations§

source§

impl Clone for UnsignedFixedDecimal

source§

fn clone(&self) -> UnsignedFixedDecimal

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for UnsignedFixedDecimal

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for UnsignedFixedDecimal

source§

fn default() -> Self

Returns a UnsignedFixedDecimal representing zero.

source§

impl Display for UnsignedFixedDecimal

This trait is implemented for compatibility with fmt!. To create a string, [Writeable::write_to_string] is usually more efficient.

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<u128> for UnsignedFixedDecimal

source§

fn from(value: u128) -> Self

Converts to this type from the input type.
source§

impl From<u16> for UnsignedFixedDecimal

source§

fn from(value: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for UnsignedFixedDecimal

source§

fn from(value: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for UnsignedFixedDecimal

source§

fn from(value: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for UnsignedFixedDecimal

source§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

impl From<usize> for UnsignedFixedDecimal

source§

fn from(value: usize) -> Self

Converts to this type from the input type.
source§

impl FromStr for UnsignedFixedDecimal

source§

type Err = ParseError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq for UnsignedFixedDecimal

source§

fn eq(&self, other: &UnsignedFixedDecimal) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Writeable for UnsignedFixedDecimal

Render the FixedDecimal as a string of ASCII digits with a possible decimal point.

§Examples

assert_writeable_eq!(UnsignedFixedDecimal::from(42u32), "42");
source§

fn write_to<W: Write + ?Sized>(&self, sink: &mut W) -> Result

Writes a string to the given sink. Errors from the sink are bubbled up. The default implementation delegates to write_to_parts, and discards any Part annotations.
source§

fn writeable_length_hint(&self) -> LengthHint

Returns a hint for the number of UTF-8 bytes that will be written to the sink. Read more
§

fn write_to_parts<S>(&self, sink: &mut S) -> Result<(), Error>
where S: PartsWrite + ?Sized,

Write bytes and 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>

Creates a new String with the data from this Writeable. Like ToString, but smaller and faster. Read more
source§

impl StructuralPartialEq for UnsignedFixedDecimal

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.