#[repr(transparent)]pub struct OrderedDecimal<D>(pub D);
Expand description
A wrapper for a decimal number that provides an implementation of Ord
and Hash
.
Like the OrderedFloat
type provided by the ordered_float
crate, but
for decimals.
NaN is treated as equal to itself and greater than all non-NaN values. All
other values are compared via their PartialOrd
implementation.
At the moment OrderedDecimal
can only wrap Decimal64
and
Decimal128
. Support for Decimal32
is not planned,
but support for Decimal<N>
would be welcomed, provided a
suitable implementation can be found.
Note that the order used by OrderedDecimal
is not the same as the order
used by the total_cmp
method. The total_cmp
method takes exponents into account and therefore does not consider e.g.
1.2
and 1.20
to be equal.
Tuple Fields§
§0: D
Implementations§
Source§impl<D> OrderedDecimal<D>
impl<D> OrderedDecimal<D>
Sourcepub fn into_inner(self) -> D
pub fn into_inner(self) -> D
Consumes the ordered decimal wrapper, returning the decimal within.
Trait Implementations§
Source§impl<D> Add<D> for OrderedDecimal<D>where
D: Add<Output = D>,
impl<D> Add<D> for OrderedDecimal<D>where
D: Add<Output = D>,
Source§impl Add<OrderedDecimal<Decimal128>> for Decimal128
impl Add<OrderedDecimal<Decimal128>> for Decimal128
Source§type Output = Decimal128
type Output = Decimal128
+
operator.Source§fn add(self, other: OrderedDecimal<Decimal128>) -> Self
fn add(self, other: OrderedDecimal<Decimal128>) -> Self
+
operation. Read moreSource§impl<D> Add for OrderedDecimal<D>where
D: Add<Output = D>,
impl<D> Add for OrderedDecimal<D>where
D: Add<Output = D>,
Source§type Output = OrderedDecimal<D>
type Output = OrderedDecimal<D>
+
operator.Source§fn add(self, other: OrderedDecimal<D>) -> Self
fn add(self, other: OrderedDecimal<D>) -> Self
+
operation. Read moreSource§impl<D> AddAssign<D> for OrderedDecimal<D>
impl<D> AddAssign<D> for OrderedDecimal<D>
Adds inner directly.
Source§fn add_assign(&mut self, other: D)
fn add_assign(&mut self, other: D)
+=
operation. Read moreSource§impl<D> AddAssign for OrderedDecimal<D>where
D: AddAssign,
impl<D> AddAssign for OrderedDecimal<D>where
D: AddAssign,
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+=
operation. Read moreSource§impl<D: Clone> Clone for OrderedDecimal<D>
impl<D: Clone> Clone for OrderedDecimal<D>
Source§fn clone(&self) -> OrderedDecimal<D>
fn clone(&self) -> OrderedDecimal<D>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<D: Debug> Debug for OrderedDecimal<D>
impl<D: Debug> Debug for OrderedDecimal<D>
Source§impl<D> Default for OrderedDecimal<D>where
D: Default,
impl<D> Default for OrderedDecimal<D>where
D: Default,
Source§impl<'de, D> Deserialize<'de> for OrderedDecimal<D>where
D: Deserialize<'de>,
impl<'de, D> Deserialize<'de> for OrderedDecimal<D>where
D: Deserialize<'de>,
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>,
Source§impl<D> Display for OrderedDecimal<D>where
D: Display,
impl<D> Display for OrderedDecimal<D>where
D: Display,
Source§impl<D> Div<D> for OrderedDecimal<D>where
D: Div<Output = D>,
impl<D> Div<D> for OrderedDecimal<D>where
D: Div<Output = D>,
Source§impl Div<OrderedDecimal<Decimal128>> for Decimal128
impl Div<OrderedDecimal<Decimal128>> for Decimal128
Source§type Output = Decimal128
type Output = Decimal128
/
operator.Source§fn div(self, other: OrderedDecimal<Decimal128>) -> Self
fn div(self, other: OrderedDecimal<Decimal128>) -> Self
/
operation. Read moreSource§impl<D> Div for OrderedDecimal<D>where
D: Div<Output = D>,
impl<D> Div for OrderedDecimal<D>where
D: Div<Output = D>,
Source§type Output = OrderedDecimal<D>
type Output = OrderedDecimal<D>
/
operator.Source§fn div(self, other: OrderedDecimal<D>) -> Self
fn div(self, other: OrderedDecimal<D>) -> Self
/
operation. Read moreSource§impl<D> DivAssign<D> for OrderedDecimal<D>
impl<D> DivAssign<D> for OrderedDecimal<D>
Divs inner directly.
Source§fn div_assign(&mut self, other: D)
fn div_assign(&mut self, other: D)
/=
operation. Read moreSource§impl<D> DivAssign for OrderedDecimal<D>where
D: DivAssign,
impl<D> DivAssign for OrderedDecimal<D>where
D: DivAssign,
Source§fn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
/=
operation. Read moreSource§impl<D> From<Decimal128> for OrderedDecimal<D>where
D: From<Decimal128>,
impl<D> From<Decimal128> for OrderedDecimal<D>where
D: From<Decimal128>,
Source§fn from(n: Decimal128) -> OrderedDecimal<D>
fn from(n: Decimal128) -> OrderedDecimal<D>
Source§impl<D> From<Decimal32> for OrderedDecimal<D>
impl<D> From<Decimal32> for OrderedDecimal<D>
Source§fn from(n: Decimal32) -> OrderedDecimal<D>
fn from(n: Decimal32) -> OrderedDecimal<D>
Source§impl<D> From<Decimal64> for OrderedDecimal<D>
impl<D> From<Decimal64> for OrderedDecimal<D>
Source§fn from(n: Decimal64) -> OrderedDecimal<D>
fn from(n: Decimal64) -> OrderedDecimal<D>
Source§impl<D> From<i32> for OrderedDecimal<D>
impl<D> From<i32> for OrderedDecimal<D>
Source§fn from(n: i32) -> OrderedDecimal<D>
fn from(n: i32) -> OrderedDecimal<D>
Source§impl<D> From<u32> for OrderedDecimal<D>
impl<D> From<u32> for OrderedDecimal<D>
Source§fn from(n: u32) -> OrderedDecimal<D>
fn from(n: u32) -> OrderedDecimal<D>
Source§impl<D> FromStr for OrderedDecimal<D>where
D: FromStr<Err = ParseDecimalError>,
impl<D> FromStr for OrderedDecimal<D>where
D: FromStr<Err = ParseDecimalError>,
Source§type Err = ParseDecimalError
type Err = ParseDecimalError
Source§fn from_str(s: &str) -> Result<OrderedDecimal<D>, ParseDecimalError>
fn from_str(s: &str) -> Result<OrderedDecimal<D>, ParseDecimalError>
s
to return a value of this type. Read moreSource§impl Hash for OrderedDecimal<Decimal128>
impl Hash for OrderedDecimal<Decimal128>
Source§impl Hash for OrderedDecimal<Decimal64>
impl Hash for OrderedDecimal<Decimal64>
Source§impl<D> Mul<D> for OrderedDecimal<D>where
D: Mul<Output = D>,
impl<D> Mul<D> for OrderedDecimal<D>where
D: Mul<Output = D>,
Source§impl Mul<OrderedDecimal<Decimal128>> for Decimal128
impl Mul<OrderedDecimal<Decimal128>> for Decimal128
Source§type Output = Decimal128
type Output = Decimal128
*
operator.Source§fn mul(self, other: OrderedDecimal<Decimal128>) -> Self
fn mul(self, other: OrderedDecimal<Decimal128>) -> Self
*
operation. Read moreSource§impl<D> Mul for OrderedDecimal<D>where
D: Mul<Output = D>,
impl<D> Mul for OrderedDecimal<D>where
D: Mul<Output = D>,
Source§type Output = OrderedDecimal<D>
type Output = OrderedDecimal<D>
*
operator.Source§fn mul(self, other: OrderedDecimal<D>) -> Self
fn mul(self, other: OrderedDecimal<D>) -> Self
*
operation. Read moreSource§impl<D> MulAssign<D> for OrderedDecimal<D>
impl<D> MulAssign<D> for OrderedDecimal<D>
Muls inner directly.
Source§fn mul_assign(&mut self, other: D)
fn mul_assign(&mut self, other: D)
*=
operation. Read moreSource§impl<D> MulAssign for OrderedDecimal<D>where
D: MulAssign,
impl<D> MulAssign for OrderedDecimal<D>where
D: MulAssign,
Source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
*=
operation. Read moreSource§impl<D> Neg for OrderedDecimal<D>where
D: Neg<Output = D>,
impl<D> Neg for OrderedDecimal<D>where
D: Neg<Output = D>,
Source§impl<const N: usize> Ord for OrderedDecimal<Decimal<N>>
impl<const N: usize> Ord for OrderedDecimal<Decimal<N>>
Source§impl Ord for OrderedDecimal<Decimal128>
impl Ord for OrderedDecimal<Decimal128>
Source§impl Ord for OrderedDecimal<Decimal64>
impl Ord for OrderedDecimal<Decimal64>
Source§impl<D> PartialEq for OrderedDecimal<D>where
Self: Ord,
impl<D> PartialEq for OrderedDecimal<D>where
Self: Ord,
Source§impl<D> PartialOrd for OrderedDecimal<D>where
Self: Ord,
impl<D> PartialOrd for OrderedDecimal<D>where
Self: Ord,
Source§impl<'a, D> Product<&'a OrderedDecimal<D>> for OrderedDecimal<D>
impl<'a, D> Product<&'a OrderedDecimal<D>> for OrderedDecimal<D>
Source§fn product<I>(iter: I) -> Selfwhere
I: Iterator<Item = &'a OrderedDecimal<D>>,
fn product<I>(iter: I) -> Selfwhere
I: Iterator<Item = &'a OrderedDecimal<D>>,
Self
from the elements by multiplying
the items.Source§impl<D> Product for OrderedDecimal<D>where
D: Product,
impl<D> Product for OrderedDecimal<D>where
D: Product,
Source§fn product<I>(iter: I) -> Selfwhere
I: Iterator<Item = OrderedDecimal<D>>,
fn product<I>(iter: I) -> Selfwhere
I: Iterator<Item = OrderedDecimal<D>>,
Self
from the elements by multiplying
the items.Source§impl<D> Rem<D> for OrderedDecimal<D>where
D: Rem<Output = D>,
impl<D> Rem<D> for OrderedDecimal<D>where
D: Rem<Output = D>,
Source§impl Rem<OrderedDecimal<Decimal128>> for Decimal128
impl Rem<OrderedDecimal<Decimal128>> for Decimal128
Source§type Output = Decimal128
type Output = Decimal128
%
operator.Source§fn rem(self, other: OrderedDecimal<Decimal128>) -> Self
fn rem(self, other: OrderedDecimal<Decimal128>) -> Self
%
operation. Read moreSource§impl<D> Rem for OrderedDecimal<D>where
D: Rem<Output = D>,
impl<D> Rem for OrderedDecimal<D>where
D: Rem<Output = D>,
Source§type Output = OrderedDecimal<D>
type Output = OrderedDecimal<D>
%
operator.Source§fn rem(self, other: OrderedDecimal<D>) -> Self
fn rem(self, other: OrderedDecimal<D>) -> Self
%
operation. Read moreSource§impl<D> RemAssign<D> for OrderedDecimal<D>
impl<D> RemAssign<D> for OrderedDecimal<D>
Rems inner directly.
Source§fn rem_assign(&mut self, other: D)
fn rem_assign(&mut self, other: D)
%=
operation. Read moreSource§impl<D> RemAssign for OrderedDecimal<D>where
D: RemAssign,
impl<D> RemAssign for OrderedDecimal<D>where
D: RemAssign,
Source§fn rem_assign(&mut self, other: Self)
fn rem_assign(&mut self, other: Self)
%=
operation. Read moreSource§impl<D> Serialize for OrderedDecimal<D>where
D: Serialize,
impl<D> Serialize for OrderedDecimal<D>where
D: Serialize,
Source§impl<D> Sub<D> for OrderedDecimal<D>where
D: Sub<Output = D>,
impl<D> Sub<D> for OrderedDecimal<D>where
D: Sub<Output = D>,
Source§impl Sub<OrderedDecimal<Decimal128>> for Decimal128
impl Sub<OrderedDecimal<Decimal128>> for Decimal128
Source§type Output = Decimal128
type Output = Decimal128
-
operator.Source§fn sub(self, other: OrderedDecimal<Decimal128>) -> Self
fn sub(self, other: OrderedDecimal<Decimal128>) -> Self
-
operation. Read moreSource§impl<D> Sub for OrderedDecimal<D>where
D: Sub<Output = D>,
impl<D> Sub for OrderedDecimal<D>where
D: Sub<Output = D>,
Source§type Output = OrderedDecimal<D>
type Output = OrderedDecimal<D>
-
operator.Source§fn sub(self, other: OrderedDecimal<D>) -> Self
fn sub(self, other: OrderedDecimal<D>) -> Self
-
operation. Read moreSource§impl<D> SubAssign<D> for OrderedDecimal<D>
impl<D> SubAssign<D> for OrderedDecimal<D>
Subs inner directly.
Source§fn sub_assign(&mut self, other: D)
fn sub_assign(&mut self, other: D)
-=
operation. Read moreSource§impl<D> SubAssign for OrderedDecimal<D>where
D: SubAssign,
impl<D> SubAssign for OrderedDecimal<D>where
D: SubAssign,
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-=
operation. Read moreSource§impl<'a, D> Sum<&'a OrderedDecimal<D>> for OrderedDecimal<D>
impl<'a, D> Sum<&'a OrderedDecimal<D>> for OrderedDecimal<D>
Source§fn sum<I>(iter: I) -> Selfwhere
I: Iterator<Item = &'a OrderedDecimal<D>>,
fn sum<I>(iter: I) -> Selfwhere
I: Iterator<Item = &'a OrderedDecimal<D>>,
Self
from the elements by “summing up”
the items.Source§impl<D> Sum for OrderedDecimal<D>where
D: Sum,
impl<D> Sum for OrderedDecimal<D>where
D: Sum,
Source§fn sum<I>(iter: I) -> Selfwhere
I: Iterator<Item = OrderedDecimal<D>>,
fn sum<I>(iter: I) -> Selfwhere
I: Iterator<Item = OrderedDecimal<D>>,
Self
from the elements by “summing up”
the items.