Crate rust_decimal_ext

Source
Expand description

rust_decimal_ext is an extension library that adds more operator trait support to rust_decimal. With this library, you can conveniently perform a variety of arithmetic operations, such as addition, subtraction, multiplication, and division, on Decimal types. It also supports automatic conversion and operations with numbers, strings, and other types.

§Usage

use rust_decimal_ext::prelude::*;

let mut a: Decimal = Decimal::from(1) + 1;
let mut b = Decimal::from(1) + 2.5;
let mut c = Decimal::from(10) + "5.5";

a += 1;
b += 2.5;
c += "5.5";

assert!(a == 3);
assert!(b == 6);
assert!(c == "21");

assert!(a > 2);
assert!(b < 10);
assert!(c >= "20");
assert!(c <= "21");

a.partial_cmp(&10).unwrap();
a.partial_cmp(&10.0).unwrap();
a.partial_cmp("10").unwrap();

// painc
_ = Decimal::from(1) + f64::NAN;
_ = Decimal::from(1) + f64::INFINITY;
_ = Decimal::from(1) + f64::NEG_INFINITY;

Modules§

prelude
A convenience module appropriate for glob imports (use rust_decimal::prelude::*;).
serdeserde and (serde-with-str or serde-with-float or serde-with-arbitrary-precision)
Serde specific functionality to customize how a decimal is serialized/deserialized (serde_with)

Structs§

Decimal
Decimal represents a 128 bit representation of a fixed-precision decimal number. The finite set of values of type Decimal are of the form m / 10e, where m is an integer such that -296 < m < 296, and e is an integer between 0 and 28 inclusive.

Enums§

Error
Error type for the library.
RoundingStrategy
RoundingStrategy represents the different rounding strategies that can be used by round_dp_with_strategy.

Traits§

MathematicalOpsmaths
Trait exposing various mathematical operations that can be applied using a Decimal. This is only present when the maths feature has been enabled, e.g. by adding the crate with

Type Aliases§

Result
Shortcut for core::result::Result<T, rust_decimal::Error>. Useful to distinguish between rust_decimal and std types.