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>

source

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>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the + operator.
source§

fn add(self, other: D) -> Self

Performs the + operation. Read more
source§

impl Add<OrderedDecimal<Decimal128>> for Decimal128

§

type Output = Decimal128

The resulting type after applying the + operator.
source§

fn add(self, other: OrderedDecimal<Decimal128>) -> Self

Performs the + operation. Read more
source§

impl Add<OrderedDecimal<Decimal64>> for Decimal64

§

type Output = Decimal64

The resulting type after applying the + operator.
source§

fn add(self, other: OrderedDecimal<Decimal64>) -> Self

Performs the + operation. Read more
source§

impl<D> Add for OrderedDecimal<D>
where D: Add<Output = D>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the + operator.
source§

fn add(self, other: OrderedDecimal<D>) -> Self

Performs the + operation. Read more
source§

impl<D> AddAssign<D> for OrderedDecimal<D>
where D: Add<Output = D> + Copy,

Adds inner directly.

source§

fn add_assign(&mut self, other: D)

Performs the += operation. Read more
source§

impl<D> AddAssign for OrderedDecimal<D>
where D: AddAssign,

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl<D: Clone> Clone for OrderedDecimal<D>

source§

fn clone(&self) -> OrderedDecimal<D>

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<D: Debug> Debug for OrderedDecimal<D>

source§

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

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

impl<D> Default for OrderedDecimal<D>
where D: Default,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<D> Display for OrderedDecimal<D>
where D: Display,

source§

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

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

impl<D> Div<D> for OrderedDecimal<D>
where D: Div<Output = D>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the / operator.
source§

fn div(self, other: D) -> Self

Performs the / operation. Read more
source§

impl Div<OrderedDecimal<Decimal128>> for Decimal128

§

type Output = Decimal128

The resulting type after applying the / operator.
source§

fn div(self, other: OrderedDecimal<Decimal128>) -> Self

Performs the / operation. Read more
source§

impl Div<OrderedDecimal<Decimal64>> for Decimal64

§

type Output = Decimal64

The resulting type after applying the / operator.
source§

fn div(self, other: OrderedDecimal<Decimal64>) -> Self

Performs the / operation. Read more
source§

impl<D> Div for OrderedDecimal<D>
where D: Div<Output = D>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the / operator.
source§

fn div(self, other: OrderedDecimal<D>) -> Self

Performs the / operation. Read more
source§

impl<D> DivAssign<D> for OrderedDecimal<D>
where D: Div<Output = D> + Copy,

Divs inner directly.

source§

fn div_assign(&mut self, other: D)

Performs the /= operation. Read more
source§

impl<D> DivAssign for OrderedDecimal<D>
where D: DivAssign,

source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
source§

impl<D> From<Decimal128> for OrderedDecimal<D>
where D: From<Decimal128>,

source§

fn from(n: Decimal128) -> OrderedDecimal<D>

Converts to this type from the input type.
source§

impl<D> From<Decimal32> for OrderedDecimal<D>
where D: From<Decimal32>,

source§

fn from(n: Decimal32) -> OrderedDecimal<D>

Converts to this type from the input type.
source§

impl<D> From<Decimal64> for OrderedDecimal<D>
where D: From<Decimal64>,

source§

fn from(n: Decimal64) -> OrderedDecimal<D>

Converts to this type from the input type.
source§

impl<D> From<i32> for OrderedDecimal<D>
where D: From<i32>,

source§

fn from(n: i32) -> OrderedDecimal<D>

Converts to this type from the input type.
source§

impl<D> From<u32> for OrderedDecimal<D>
where D: From<u32>,

source§

fn from(n: u32) -> OrderedDecimal<D>

Converts to this type from the input type.
source§

impl<D> FromStr for OrderedDecimal<D>
where D: FromStr<Err = ParseDecimalError>,

§

type Err = ParseDecimalError

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

fn from_str(s: &str) -> Result<OrderedDecimal<D>, ParseDecimalError>

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

impl<const N: usize> Hash for OrderedDecimal<Decimal<N>>

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Hash for OrderedDecimal<Decimal128>

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Hash for OrderedDecimal<Decimal64>

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<D> Mul<D> for OrderedDecimal<D>
where D: Mul<Output = D>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the * operator.
source§

fn mul(self, other: D) -> Self

Performs the * operation. Read more
source§

impl Mul<OrderedDecimal<Decimal128>> for Decimal128

§

type Output = Decimal128

The resulting type after applying the * operator.
source§

fn mul(self, other: OrderedDecimal<Decimal128>) -> Self

Performs the * operation. Read more
source§

impl Mul<OrderedDecimal<Decimal64>> for Decimal64

§

type Output = Decimal64

The resulting type after applying the * operator.
source§

fn mul(self, other: OrderedDecimal<Decimal64>) -> Self

Performs the * operation. Read more
source§

impl<D> Mul for OrderedDecimal<D>
where D: Mul<Output = D>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the * operator.
source§

fn mul(self, other: OrderedDecimal<D>) -> Self

Performs the * operation. Read more
source§

impl<D> MulAssign<D> for OrderedDecimal<D>
where D: Mul<Output = D> + Copy,

Muls inner directly.

source§

fn mul_assign(&mut self, other: D)

Performs the *= operation. Read more
source§

impl<D> MulAssign for OrderedDecimal<D>
where D: MulAssign,

source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
source§

impl<D> Neg for OrderedDecimal<D>
where D: Neg<Output = D>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl<const N: usize> Ord for OrderedDecimal<Decimal<N>>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl Ord for OrderedDecimal<Decimal128>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl Ord for OrderedDecimal<Decimal64>

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<D> PartialEq for OrderedDecimal<D>
where Self: Ord,

source§

fn eq(&self, other: &Self) -> 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<D> PartialOrd for OrderedDecimal<D>
where Self: Ord,

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, D> Product<&'a OrderedDecimal<D>> for OrderedDecimal<D>
where D: Product<&'a D> + 'a,

source§

fn product<I>(iter: I) -> Self
where I: Iterator<Item = &'a OrderedDecimal<D>>,

Takes an iterator and generates Self from the elements by multiplying the items.
source§

impl<D> Product for OrderedDecimal<D>
where D: Product,

source§

fn product<I>(iter: I) -> Self
where I: Iterator<Item = OrderedDecimal<D>>,

Takes an iterator and generates Self from the elements by multiplying the items.
source§

impl<D> Rem<D> for OrderedDecimal<D>
where D: Rem<Output = D>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the % operator.
source§

fn rem(self, other: D) -> Self

Performs the % operation. Read more
source§

impl Rem<OrderedDecimal<Decimal128>> for Decimal128

§

type Output = Decimal128

The resulting type after applying the % operator.
source§

fn rem(self, other: OrderedDecimal<Decimal128>) -> Self

Performs the % operation. Read more
source§

impl Rem<OrderedDecimal<Decimal64>> for Decimal64

§

type Output = Decimal64

The resulting type after applying the % operator.
source§

fn rem(self, other: OrderedDecimal<Decimal64>) -> Self

Performs the % operation. Read more
source§

impl<D> Rem for OrderedDecimal<D>
where D: Rem<Output = D>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the % operator.
source§

fn rem(self, other: OrderedDecimal<D>) -> Self

Performs the % operation. Read more
source§

impl<D> RemAssign<D> for OrderedDecimal<D>
where D: Rem<Output = D> + Copy,

Rems inner directly.

source§

fn rem_assign(&mut self, other: D)

Performs the %= operation. Read more
source§

impl<D> RemAssign for OrderedDecimal<D>
where D: RemAssign,

source§

fn rem_assign(&mut self, other: Self)

Performs the %= operation. Read more
source§

impl<D> Serialize for OrderedDecimal<D>
where D: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<D> Sub<D> for OrderedDecimal<D>
where D: Sub<Output = D>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the - operator.
source§

fn sub(self, other: D) -> Self

Performs the - operation. Read more
source§

impl Sub<OrderedDecimal<Decimal128>> for Decimal128

§

type Output = Decimal128

The resulting type after applying the - operator.
source§

fn sub(self, other: OrderedDecimal<Decimal128>) -> Self

Performs the - operation. Read more
source§

impl Sub<OrderedDecimal<Decimal64>> for Decimal64

§

type Output = Decimal64

The resulting type after applying the - operator.
source§

fn sub(self, other: OrderedDecimal<Decimal64>) -> Self

Performs the - operation. Read more
source§

impl<D> Sub for OrderedDecimal<D>
where D: Sub<Output = D>,

§

type Output = OrderedDecimal<D>

The resulting type after applying the - operator.
source§

fn sub(self, other: OrderedDecimal<D>) -> Self

Performs the - operation. Read more
source§

impl<D> SubAssign<D> for OrderedDecimal<D>
where D: Sub<Output = D> + Copy,

Subs inner directly.

source§

fn sub_assign(&mut self, other: D)

Performs the -= operation. Read more
source§

impl<D> SubAssign for OrderedDecimal<D>
where D: SubAssign,

source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
source§

impl<'a, D> Sum<&'a OrderedDecimal<D>> for OrderedDecimal<D>
where D: Sum<&'a D> + 'a,

source§

fn sum<I>(iter: I) -> Self
where I: Iterator<Item = &'a OrderedDecimal<D>>,

Takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl<D> Sum for OrderedDecimal<D>
where D: Sum,

source§

fn sum<I>(iter: I) -> Self
where I: Iterator<Item = OrderedDecimal<D>>,

Takes an iterator and generates Self from the elements by “summing up” the items.
source§

impl<D: Copy> Copy for OrderedDecimal<D>

source§

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

default 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> CloneToUninit for T
where T: Copy,

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> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,