[][src]Struct fraction::GenericDecimal

pub struct GenericDecimal<T, P>(_, _)
where
    T: Clone + Integer,
    P: Copy + Integer + Into<usize>
;

Decimal type implementation

T is the type for data P is the type for precision

Uses GenericFraction internally to represent the data. Precision is being used for representation purposes only. Calculations do not use precision, but comparison does.

Examples

use fraction::GenericDecimal;

type Decimal = GenericDecimal<u64, u8>;

let d1 = Decimal::from(12);
let d2 = Decimal::from(0.5);

let mul = d1 * d2;
let div = d1 / d2;
let add = d1 + d2;

assert_eq!(mul, 6.into());
assert_eq!(div, Decimal::from("24.00"));
assert_eq!(add, Decimal::from(12.5));

Methods

impl<T, P> GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Convert from a GenericFraction

Automatically calculates precision, so for "bad" numbers may take a lot of CPU cycles, especially if precision represented by big types (e.g. usize)

Examples

use fraction::{Fraction, Decimal};

let from_fraction = Decimal::from_fraction(Fraction::new(1u64, 3u64));
let from_division = Decimal::from(1) / Decimal::from(3);

let d1 = Decimal::from(4) / from_fraction;
let d2 = Decimal::from(4) / from_division;

assert_eq!(d1, d2);
assert_eq!(d1, Decimal::from(12));

Trait Implementations

impl<T, F, P1, P2> TryToConvertFrom<GenericDecimal<F, P1>> for GenericDecimal<T, P2> where
    T: Copy + Integer + TryToConvertFrom<F>,
    F: Copy + Integer,
    P2: Copy + Integer + Into<usize> + TryToConvertFrom<P1>,
    P1: Copy + Integer + Into<usize>, 
[src]

impl<T, P> PartialOrd<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + PartialOrd,
    P: Copy + GenericInteger + Into<usize>, 
[src]

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

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

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

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

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

impl<T, P> PartialEq<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + PartialEq,
    P: Copy + GenericInteger + Into<usize>, 
[src]

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

This method tests for !=.

impl<T, P> From<f32> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize> + From<u8>, 
[src]

Performs the conversion.

impl<T, P> From<f64> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize> + From<u8>, 
[src]

Performs the conversion.

impl<T, P> From<u8> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<i8> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<u16> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<i16> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<u32> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<i32> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<u64> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<i64> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<u128> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<i128> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<usize> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<isize> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<'a, T, P> From<&'a str> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize> + From<u8>, 
[src]

Performs the conversion.

impl<T, P> From<BigUint> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> From<BigInt> for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the conversion.

impl<T: Clone, P: Clone> Clone for GenericDecimal<T, P> where
    T: Clone + Integer,
    P: Copy + Integer + Into<usize>, 
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T, P> Copy for GenericDecimal<T, P> where
    T: Copy + Integer,
    P: Copy + Integer + Into<usize>, 
[src]

impl<T, P> Eq for GenericDecimal<T, P> where
    T: Clone + GenericInteger + Eq,
    P: Copy + GenericInteger + Into<usize>, 
[src]

impl<T, P> Debug for GenericDecimal<T, P> where
    T: Clone + GenericInteger + From<u8> + ToPrimitive + Debug,
    P: Copy + Integer + Into<usize>, 
[src]

Formats the value using the given formatter. Read more

impl<T, P> Display for GenericDecimal<T, P> where
    T: Clone + GenericInteger + From<u8> + ToPrimitive + Display,
    P: Copy + Integer + Into<usize>, 
[src]

Formats the value using the given formatter. Read more

impl<T, P> Sub<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + Sub,
    P: Copy + GenericInteger + Into<usize>, 
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<'a, T, P> Sub<&'a GenericDecimal<T, P>> for &'a GenericDecimal<T, P> where
    T: Clone + GenericInteger + Sub,
    P: Copy + GenericInteger + Into<usize>,
    &'a T: Sub<Output = T>, 
[src]

The resulting type after applying the - operator.

Performs the - operation.

impl<T, P> Add<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + Add,
    P: Copy + GenericInteger + Into<usize>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<'a, T, P> Add<&'a GenericDecimal<T, P>> for &'a GenericDecimal<T, P> where
    T: Clone + GenericInteger + Add,
    P: Copy + GenericInteger + Into<usize>,
    &'a T: Add<Output = T>, 
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl<T, P> Mul<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + Mul,
    P: Copy + GenericInteger + Into<usize>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<'a, T, P> Mul<&'a GenericDecimal<T, P>> for &'a GenericDecimal<T, P> where
    T: Clone + GenericInteger + Mul,
    P: Copy + GenericInteger + Into<usize>,
    &'a T: Mul<Output = T>, 
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl<T, P> Div<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + Div,
    P: Copy + GenericInteger + Into<usize>, 
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<'a, T, P> Div<&'a GenericDecimal<T, P>> for &'a GenericDecimal<T, P> where
    T: Clone + GenericInteger + Div,
    P: Copy + GenericInteger + Into<usize>,
    &'a T: Div<Output = T>, 
[src]

The resulting type after applying the / operator.

Performs the / operation.

impl<T, P> Rem<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + Rem,
    P: Copy + GenericInteger + Into<usize>, 
[src]

The resulting type after applying the % operator.

Performs the % operation.

impl<'a, T, P> Rem<&'a GenericDecimal<T, P>> for &'a GenericDecimal<T, P> where
    T: Clone + GenericInteger + Rem,
    P: Copy + GenericInteger + Into<usize>,
    &'a T: Rem<Output = T>, 
[src]

The resulting type after applying the % operator.

Performs the % operation.

impl<T, P> Neg for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + Integer + Into<usize>, 
[src]

The resulting type after applying the - operator.

Performs the unary - operation.

impl<'a, T, P> Neg for &'a GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + Integer + Into<usize>,
    &'a T: Neg<Output = T>, 
[src]

The resulting type after applying the - operator.

Performs the unary - operation.

impl<T, P> AddAssign<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + DivAssign + SubAssign + MulAssign + AddAssign,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the += operation.

impl<'a, T, P> AddAssign<&'a GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + Integer + AddAssign + AddAssign<&'a T>,
    P: Copy + Integer + Into<usize>, 
[src]

Performs the += operation.

impl<T, P> SubAssign<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + DivAssign + SubAssign + MulAssign + SubAssign,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the -= operation.

impl<'a, T, P> SubAssign<&'a GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + Integer + SubAssign + SubAssign<&'a T>,
    P: Copy + Integer + Into<usize>, 
[src]

Performs the -= operation.

impl<T, P> MulAssign<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + DivAssign + SubAssign + MulAssign + MulAssign,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the *= operation.

impl<'a, T, P> MulAssign<&'a GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + Integer + MulAssign + MulAssign<&'a T>,
    P: Copy + Integer + Into<usize>, 
[src]

Performs the *= operation.

impl<T, P> DivAssign<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + DivAssign + SubAssign + MulAssign + DivAssign,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the /= operation.

impl<'a, T, P> DivAssign<&'a GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + Integer + DivAssign + DivAssign<&'a T>,
    P: Copy + Integer + Into<usize>, 
[src]

Performs the /= operation.

impl<T, P> RemAssign<GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + GenericInteger + DivAssign + SubAssign + MulAssign + RemAssign,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Performs the %= operation.

impl<'a, T, P> RemAssign<&'a GenericDecimal<T, P>> for GenericDecimal<T, P> where
    T: Clone + Integer + RemAssign + RemAssign<&'a T>,
    P: Copy + Integer + Into<usize>, 
[src]

Performs the %= operation.

impl<T, P> Hash for GenericDecimal<T, P> where
    T: Clone + GenericInteger + PartialEq,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Feeds this value into the given [Hasher]. Read more

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

impl<T, P> ToPrimitive for GenericDecimal<T, P> where
    T: Clone + GenericInteger + ToPrimitive,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Converts the value of self to an i64.

Converts the value of self to an u64.

Converts the value of self to an f64.

Converts the value of self to an isize.

Converts the value of self to an i8.

Converts the value of self to an i16.

Converts the value of self to an i32.

Converts the value of self to an i128. Read more

Converts the value of self to a usize.

Converts the value of self to an u8.

Converts the value of self to an u16.

Converts the value of self to an u32.

Converts the value of self to an u128. Read more

Converts the value of self to an f32.

impl<T, P> Num for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize> + From<u8>, 
[src]

Convert from a string and radix <= 36. Read more

impl<T, P> Bounded for GenericDecimal<T, P> where
    T: Clone + GenericInteger + Bounded,
    P: Copy + GenericInteger + Into<usize> + Bounded
[src]

returns the smallest finite number this type can represent

returns the largest finite number this type can represent

impl<T, P> Zero for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize> + Zero
[src]

Returns the additive identity element of Self, 0. Read more

Returns true if self is equal to the additive identity.

impl<T, P> One for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Returns the multiplicative identity element of Self, 1. Read more

Returns true if self is equal to the multiplicative identity. Read more

impl<T, P> CheckedSub for GenericDecimal<T, P> where
    T: Clone + GenericInteger + CheckedAdd + CheckedDiv + CheckedMul + CheckedSub + CheckedSub,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Subtracts two numbers, checking for underflow. If underflow happens, None is returned. Read more

impl<T, P> CheckedAdd for GenericDecimal<T, P> where
    T: Clone + GenericInteger + CheckedAdd + CheckedDiv + CheckedMul + CheckedSub + CheckedAdd,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Adds two numbers, checking for overflow. If overflow happens, None is returned. Read more

impl<T, P> CheckedMul for GenericDecimal<T, P> where
    T: Clone + GenericInteger + CheckedAdd + CheckedDiv + CheckedMul + CheckedSub + CheckedMul,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Multiplies two numbers, checking for underflow or overflow. If underflow or overflow happens, None is returned. Read more

impl<T, P> CheckedDiv for GenericDecimal<T, P> where
    T: Clone + GenericInteger + CheckedAdd + CheckedDiv + CheckedMul + CheckedSub + CheckedDiv,
    P: Copy + GenericInteger + Into<usize>, 
[src]

Divides two numbers, checking for underflow, overflow and division by zero. If any of that happens, None is returned. Read more

impl<T, P> Signed for GenericDecimal<T, P> where
    T: Clone + GenericInteger + Neg,
    P: Copy + GenericInteger + Into<usize> + From<u8>, 
[src]

Computes the absolute value. Read more

The positive difference of two numbers. Read more

Returns the sign of the number. Read more

Returns true if the number is positive and false if the number is zero or negative.

Returns true if the number is negative and false if the number is zero or positive.

impl<T, P> Serialize for GenericDecimal<T, P> where
    T: Clone + Integer,
    P: Copy + Integer + Into<usize>,
    T: Serialize,
    P: Serialize
[src]

Serialize this value into the given Serde serializer. Read more

impl<'de, T, P> Deserialize<'de> for GenericDecimal<T, P> where
    T: Clone + Integer,
    P: Copy + Integer + Into<usize>,
    T: Deserialize<'de>,
    P: Deserialize<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl<T, P> ToInputValue for GenericDecimal<T, P> where
    T: Clone + GenericInteger + Display + From<u8>,
    P: Copy + Integer + Into<usize>, 
[src]

Performs the conversion.

impl<T, P> FromInputValue for GenericDecimal<T, P> where
    T: Clone + GenericInteger,
    P: Copy + GenericInteger + Into<usize> + From<u8>, 
[src]

Performs the conversion.

impl<T, P> GraphQLType for GenericDecimal<T, P> where
    T: Clone + GenericInteger + From<u8> + Display,
    P: Copy + GenericInteger + Into<usize> + From<u8>, 
[src]

The expected context type for this GraphQL type Read more

Type that may carry additional schema information Read more

The name of the GraphQL type to expose. Read more

The meta type representing this GraphQL type.

Resolve the provided selection set against the current object. Read more

Resolve the value of a single field on this type. Read more

Resolve this interface or union into a concrete type Read more

Return the concrete type name for this instance/union. Read more

impl<T, P> ToSql for GenericDecimal<T, P> where
    T: Clone + GenericInteger + From<u8> + Debug,
    P: Copy + GenericInteger + Into<usize> + Debug
[src]

Converts the value of self into the binary format of the specified Postgres Type, appending it to out. Read more

Determines if a value of this type can be converted to the specified Postgres Type. Read more

An adaptor method used internally by Rust-Postgres. Read more

impl<T, P> FromSql for GenericDecimal<T, P> where
    T: Clone + GenericInteger + From<u16>,
    P: Copy + GenericInteger + Into<usize> + Bounded + TryToConvertFrom<i16> + Display
[src]

Creates a new value of this type from a buffer of data of the specified Postgres Type in its binary format. Read more

Determines if a value of this type can be created from the specified Postgres Type. Read more

Creates a new value of this type from a NULL SQL value. Read more

A convenience function that delegates to from_sql and from_sql_null depending on the value of raw. Read more

Auto Trait Implementations

impl<T, P> Send for GenericDecimal<T, P> where
    P: Send,
    T: Send

impl<T, P> Sync for GenericDecimal<T, P> where
    P: Sync,
    T: Sync

Blanket Implementations

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

Performs the conversion.

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

Converts the given value to a String. Read more

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

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

🔬 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> From for T
[src]

Performs the conversion.

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

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

Immutably borrows from an owned value. Read more

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

Mutably borrows from an owned value. Read more

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

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

The type returned in the event of a conversion error.

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

Performs the conversion.

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

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T, Rhs, Output> NumOps for T where
    T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, 
[src]

impl<T> NumAssign for T where
    T: Num + NumAssignOps<T>, 
[src]

impl<T, Rhs> NumAssignOps for T where
    T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>, 
[src]

impl<T> NumAssignRef for T where
    T: NumAssign + NumAssignOps<&'r T>, 
[src]

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

impl<Q, K> Equivalent for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

Compare self to key and return true if they are equal.

impl<T> Same for T

Should always be Self