Struct dec::OrderedDecimal
source · #[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
§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>,
§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
§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>,
§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>,
§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
§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>,
§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
§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>,
§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
§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>,
§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.impl<D: Copy> Copy for OrderedDecimal<D>
impl<D> Eq for OrderedDecimal<D>where
Self: Ord,
Auto Trait Implementations§
impl<D> Freeze for OrderedDecimal<D>where
D: Freeze,
impl<D> RefUnwindSafe for OrderedDecimal<D>where
D: RefUnwindSafe,
impl<D> Send for OrderedDecimal<D>where
D: Send,
impl<D> Sync for OrderedDecimal<D>where
D: Sync,
impl<D> Unpin for OrderedDecimal<D>where
D: Unpin,
impl<D> UnwindSafe for OrderedDecimal<D>where
D: UnwindSafe,
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)