Struct dec::OrderedDecimal[][src]

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.

Implementations

impl<D> OrderedDecimal<D>[src]

pub fn into_inner(self) -> D[src]

Consumes the ordered decimal wrapper, returning the decimal within.

Trait Implementations

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

type Output = Self

The resulting type after applying the + operator.

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

Performs the + operation. Read more

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

type Output = Self

The resulting type after applying the + operator.

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

Performs the + operation. Read more

impl Add<OrderedDecimal<Decimal128>> for Decimal128[src]

type Output = Self

The resulting type after applying the + operator.

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

Performs the + operation. Read more

impl Add<OrderedDecimal<Decimal64>> for Decimal64[src]

type Output = Self

The resulting type after applying the + operator.

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

Performs the + operation. Read more

impl<D> AddAssign<D> for OrderedDecimal<D> where
    D: Add<Output = D> + Copy
[src]

Adds inner directly.

fn add_assign(&mut self, other: D)[src]

Performs the += operation. Read more

impl<D> AddAssign<OrderedDecimal<D>> for OrderedDecimal<D> where
    D: AddAssign
[src]

fn add_assign(&mut self, other: Self)[src]

Performs the += operation. Read more

impl<D: Clone> Clone for OrderedDecimal<D>[src]

fn clone(&self) -> OrderedDecimal<D>[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<D: Debug> Debug for OrderedDecimal<D>[src]

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

Formats the value using the given formatter. Read more

impl<D> Default for OrderedDecimal<D> where
    D: Default
[src]

fn default() -> Self[src]

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

impl<'de, D> Deserialize<'de> for OrderedDecimal<D> where
    D: Deserialize<'de>, 
[src]

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl<D> Display for OrderedDecimal<D> where
    D: Display
[src]

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

Formats the value using the given formatter. Read more

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

type Output = Self

The resulting type after applying the / operator.

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

Performs the / operation. Read more

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

type Output = Self

The resulting type after applying the / operator.

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

Performs the / operation. Read more

impl Div<OrderedDecimal<Decimal128>> for Decimal128[src]

type Output = Self

The resulting type after applying the / operator.

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

Performs the / operation. Read more

impl Div<OrderedDecimal<Decimal64>> for Decimal64[src]

type Output = Self

The resulting type after applying the / operator.

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

Performs the / operation. Read more

impl<D> DivAssign<D> for OrderedDecimal<D> where
    D: Div<Output = D> + Copy
[src]

Divs inner directly.

fn div_assign(&mut self, other: D)[src]

Performs the /= operation. Read more

impl<D> DivAssign<OrderedDecimal<D>> for OrderedDecimal<D> where
    D: DivAssign
[src]

fn div_assign(&mut self, other: Self)[src]

Performs the /= operation. Read more

impl<D> From<Decimal128> for OrderedDecimal<D> where
    D: From<Decimal128>, 
[src]

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

Performs the conversion.

impl<D> From<Decimal32> for OrderedDecimal<D> where
    D: From<Decimal32>, 
[src]

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

Performs the conversion.

impl<D> From<Decimal64> for OrderedDecimal<D> where
    D: From<Decimal64>, 
[src]

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

Performs the conversion.

impl<D> From<i32> for OrderedDecimal<D> where
    D: From<i32>, 
[src]

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

Performs the conversion.

impl<D> From<u32> for OrderedDecimal<D> where
    D: From<u32>, 
[src]

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

Performs the conversion.

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

type Err = ParseDecimalError

The associated error which can be returned from parsing.

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

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

impl Hash for OrderedDecimal<Decimal64>[src]

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

Feeds this value into the given Hasher. Read more

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

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

impl Hash for OrderedDecimal<Decimal128>[src]

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

Feeds this value into the given Hasher. Read more

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

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

impl<const N: usize> Hash for OrderedDecimal<Decimal<N>>[src]

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

Feeds this value into the given Hasher. Read more

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

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

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

type Output = Self

The resulting type after applying the * operator.

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

Performs the * operation. Read more

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

type Output = Self

The resulting type after applying the * operator.

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

Performs the * operation. Read more

impl Mul<OrderedDecimal<Decimal128>> for Decimal128[src]

type Output = Self

The resulting type after applying the * operator.

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

Performs the * operation. Read more

impl Mul<OrderedDecimal<Decimal64>> for Decimal64[src]

type Output = Self

The resulting type after applying the * operator.

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

Performs the * operation. Read more

impl<D> MulAssign<D> for OrderedDecimal<D> where
    D: Mul<Output = D> + Copy
[src]

Muls inner directly.

fn mul_assign(&mut self, other: D)[src]

Performs the *= operation. Read more

impl<D> MulAssign<OrderedDecimal<D>> for OrderedDecimal<D> where
    D: MulAssign
[src]

fn mul_assign(&mut self, other: Self)[src]

Performs the *= operation. Read more

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

type Output = Self

The resulting type after applying the - operator.

fn neg(self) -> Self[src]

Performs the unary - operation. Read more

impl Ord for OrderedDecimal<Decimal64>[src]

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

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl Ord for OrderedDecimal<Decimal128>[src]

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

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl<const N: usize> Ord for OrderedDecimal<Decimal<N>>[src]

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

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl<D> PartialEq<OrderedDecimal<D>> for OrderedDecimal<D> where
    Self: Ord
[src]

fn eq(&self, other: &Self) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<D> PartialOrd<OrderedDecimal<D>> for OrderedDecimal<D> where
    Self: Ord
[src]

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

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

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

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

impl<D> Product<OrderedDecimal<D>> for OrderedDecimal<D> where
    D: Product
[src]

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

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

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

type Output = Self

The resulting type after applying the % operator.

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

Performs the % operation. Read more

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

type Output = Self

The resulting type after applying the % operator.

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

Performs the % operation. Read more

impl Rem<OrderedDecimal<Decimal128>> for Decimal128[src]

type Output = Self

The resulting type after applying the % operator.

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

Performs the % operation. Read more

impl Rem<OrderedDecimal<Decimal64>> for Decimal64[src]

type Output = Self

The resulting type after applying the % operator.

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

Performs the % operation. Read more

impl<D> RemAssign<D> for OrderedDecimal<D> where
    D: Rem<Output = D> + Copy
[src]

Rems inner directly.

fn rem_assign(&mut self, other: D)[src]

Performs the %= operation. Read more

impl<D> RemAssign<OrderedDecimal<D>> for OrderedDecimal<D> where
    D: RemAssign
[src]

fn rem_assign(&mut self, other: Self)[src]

Performs the %= operation. Read more

impl<D> Serialize for OrderedDecimal<D> where
    D: Serialize
[src]

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

Serialize this value into the given Serde serializer. Read more

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

type Output = Self

The resulting type after applying the - operator.

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

Performs the - operation. Read more

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

type Output = Self

The resulting type after applying the - operator.

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

Performs the - operation. Read more

impl Sub<OrderedDecimal<Decimal128>> for Decimal128[src]

type Output = Self

The resulting type after applying the - operator.

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

Performs the - operation. Read more

impl Sub<OrderedDecimal<Decimal64>> for Decimal64[src]

type Output = Self

The resulting type after applying the - operator.

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

Performs the - operation. Read more

impl<D> SubAssign<D> for OrderedDecimal<D> where
    D: Sub<Output = D> + Copy
[src]

Subs inner directly.

fn sub_assign(&mut self, other: D)[src]

Performs the -= operation. Read more

impl<D> SubAssign<OrderedDecimal<D>> for OrderedDecimal<D> where
    D: SubAssign
[src]

fn sub_assign(&mut self, other: Self)[src]

Performs the -= operation. Read more

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

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

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

impl<D> Sum<OrderedDecimal<D>> for OrderedDecimal<D> where
    D: Sum
[src]

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

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

impl<D: Copy> Copy for OrderedDecimal<D>[src]

impl<D> Eq for OrderedDecimal<D> where
    Self: Ord
[src]

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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