Struct rust_decimal::Decimal[][src]

#[repr(C)]
pub struct Decimal { /* fields omitted */ }
Expand description

Decimal represents a 128 bit representation of a fixed-precision decimal number. The finite set of values of type Decimal are of the form m / 10e, where m is an integer such that -296 < m < 296, and e is an integer between 0 and 28 inclusive.

Implementations

impl Decimal[src]

pub const MIN: Decimal[src]

The smallest value that can be represented by this decimal type.

pub const MAX: Decimal[src]

The largest value that can be represented by this decimal type.

pub const ZERO: Decimal[src]

A constant representing 0.

pub const ONE: Decimal[src]

A constant representing 1.

#[must_use]
pub fn new(num: i64, scale: u32) -> Decimal
[src]

Returns a Decimal with a 64 bit m representation and corresponding e scale.

Arguments

  • num - An i64 that represents the m portion of the decimal number
  • scale - A u32 representing the e portion of the decimal number.

Panics

This function panics if scale is > 28.

Example

use rust_decimal::Decimal;

let pi = Decimal::new(3141, 3);
assert_eq!(pi.to_string(), "3.141");

#[must_use]
pub fn from_i128_with_scale(num: i128, scale: u32) -> Decimal
[src]

Creates a Decimal using a 128 bit signed m representation and corresponding e scale.

Arguments

  • num - An i128 that represents the m portion of the decimal number
  • scale - A u32 representing the e portion of the decimal number.

Panics

This function panics if scale is > 28 or if num exceeds the maximum supported 96 bits.

Example

use rust_decimal::Decimal;

let pi = Decimal::from_i128_with_scale(3141i128, 3);
assert_eq!(pi.to_string(), "3.141");

pub fn try_from_i128_with_scale(num: i128, scale: u32) -> Result<Decimal>[src]

Checked version of from_i128_with_scale. Will return Err instead of panicking at run-time.

Example

use rust_decimal::Decimal;

let max = Decimal::try_from_i128_with_scale(i128::MAX, u32::MAX);
assert!(max.is_err());

#[must_use]
pub const fn from_parts(
    lo: u32,
    mid: u32,
    hi: u32,
    negative: bool,
    scale: u32
) -> Decimal
[src]

Returns a Decimal using the instances constituent parts.

Arguments

  • lo - The low 32 bits of a 96-bit integer.
  • mid - The middle 32 bits of a 96-bit integer.
  • hi - The high 32 bits of a 96-bit integer.
  • negative - true to indicate a negative number.
  • scale - A power of 10 ranging from 0 to 28.

Caution: Undefined behavior

While a scale greater than 28 can be passed in, it will be automatically capped by this function at the maximum precision. The library opts towards this functionality as opposed to a panic to ensure that the function can be treated as constant. This may lead to undefined behavior in downstream applications and should be treated with caution.

Example

use rust_decimal::Decimal;

let pi = Decimal::from_parts(1102470952, 185874565, 1703060790, false, 28);
assert_eq!(pi.to_string(), "3.1415926535897932384626433832");

pub fn from_scientific(value: &str) -> Result<Decimal, Error>[src]

Returns a Result which if successful contains the Decimal constitution of the scientific notation provided by value.

Arguments

  • value - The scientific notation of the Decimal.

Example

use rust_decimal::Decimal;

let value = Decimal::from_scientific("9.7e-7").unwrap();
assert_eq!(value.to_string(), "0.00000097");

#[must_use]
pub const fn scale(&self) -> u32
[src]

Returns the scale of the decimal number, otherwise known as e.

Example

use rust_decimal::Decimal;

let num = Decimal::new(1234, 3);
assert_eq!(num.scale(), 3u32);

#[must_use]
pub const fn mantissa(&self) -> i128
[src]

Returns the mantissa of the decimal number.

Example

use rust_decimal::prelude::*;

let num = Decimal::from_str("-1.2345678").unwrap();
assert_eq!(num.mantissa(), -12345678i128);
assert_eq!(num.scale(), 7);

#[must_use]
pub const fn is_zero(&self) -> bool
[src]

Returns true if this Decimal number is equivalent to zero.

Example

use rust_decimal::prelude::*;

let num = Decimal::ZERO;
assert!(num.is_zero());

pub fn set_sign(&mut self, positive: bool)[src]

👎 Deprecated since 1.4.0:

please use set_sign_positive instead

An optimized method for changing the sign of a decimal number.

Arguments

  • positive: true if the resulting decimal should be positive.

Example

use rust_decimal::Decimal;

let mut one = Decimal::new(1, 0);
one.set_sign(false);
assert_eq!(one.to_string(), "-1");

pub fn set_sign_positive(&mut self, positive: bool)[src]

An optimized method for changing the sign of a decimal number.

Arguments

  • positive: true if the resulting decimal should be positive.

Example

use rust_decimal::Decimal;

let mut one = Decimal::new(1, 0);
one.set_sign_positive(false);
assert_eq!(one.to_string(), "-1");

pub fn set_sign_negative(&mut self, negative: bool)[src]

An optimized method for changing the sign of a decimal number.

Arguments

  • negative: true if the resulting decimal should be negative.

Example

use rust_decimal::Decimal;

let mut one = Decimal::new(1, 0);
one.set_sign_negative(true);
assert_eq!(one.to_string(), "-1");

pub fn set_scale(&mut self, scale: u32) -> Result<(), Error>[src]

An optimized method for changing the scale of a decimal number.

Arguments

  • scale: the new scale of the number

Example

use rust_decimal::Decimal;

let mut one = Decimal::new(1, 0);
one.set_scale(5).unwrap();
assert_eq!(one.to_string(), "0.00001");

pub fn rescale(&mut self, scale: u32)[src]

Modifies the Decimal to the given scale, attempting to do so without changing the underlying number itself.

Note that setting the scale to something less then the current Decimals scale will cause the newly created Decimal to have some rounding. Scales greater than the maximum precision supported by Decimal will be automatically rounded to Decimal::MAX_PRECISION. Rounding leverages the half up strategy.

Arguments

  • scale: The scale to use for the new Decimal number.

Example

use rust_decimal::Decimal;

let mut number = Decimal::new(1_123, 3);
number.rescale(6);
assert_eq!(number, Decimal::new(1_123_000, 6));
let mut round = Decimal::new(145, 2);
round.rescale(1);
assert_eq!(round, Decimal::new(15, 1));

#[must_use]
pub const fn serialize(&self) -> [u8; 16]
[src]

Returns a serialized version of the decimal number. The resulting byte array will have the following representation:

  • Bytes 1-4: flags
  • Bytes 5-8: lo portion of m
  • Bytes 9-12: mid portion of m
  • Bytes 13-16: high portion of m

#[must_use]
pub const fn deserialize(bytes: [u8; 16]) -> Decimal
[src]

Deserializes the given bytes into a decimal number. The deserialized byte representation must be 16 bytes and adhere to the following convention:

  • Bytes 1-4: flags
  • Bytes 5-8: lo portion of m
  • Bytes 9-12: mid portion of m
  • Bytes 13-16: high portion of m

#[must_use]
pub fn is_negative(&self) -> bool
[src]

👎 Deprecated since 0.6.3:

please use is_sign_negative instead

Returns true if the decimal is negative.

#[must_use]
pub fn is_positive(&self) -> bool
[src]

👎 Deprecated since 0.6.3:

please use is_sign_positive instead

Returns true if the decimal is positive.

pub const fn is_sign_negative(&self) -> bool[src]

Returns true if the sign bit of the decimal is negative.

#[must_use]
pub const fn is_sign_positive(&self) -> bool
[src]

Returns true if the sign bit of the decimal is positive.

#[must_use]
pub const fn min_value() -> Decimal
[src]

👎 Deprecated since 1.12.0:

Use the associated constant Decimal::MIN

Returns the minimum possible number that Decimal can represent.

#[must_use]
pub const fn max_value() -> Decimal
[src]

👎 Deprecated since 1.12.0:

Use the associated constant Decimal::MAX

Returns the maximum possible number that Decimal can represent.

#[must_use]
pub fn trunc(&self) -> Decimal
[src]

Returns a new Decimal integral with no fractional portion. This is a true truncation whereby no rounding is performed.

Example

use rust_decimal::Decimal;

let pi = Decimal::new(3141, 3);
let trunc = Decimal::new(3, 0);
// note that it returns a decimal
assert_eq!(pi.trunc(), trunc);

#[must_use]
pub fn fract(&self) -> Decimal
[src]

Returns a new Decimal representing the fractional portion of the number.

Example

use rust_decimal::Decimal;

let pi = Decimal::new(3141, 3);
let fract = Decimal::new(141, 3);
// note that it returns a decimal
assert_eq!(pi.fract(), fract);

#[must_use]
pub fn abs(&self) -> Decimal
[src]

Computes the absolute value of self.

Example

use rust_decimal::Decimal;

let num = Decimal::new(-3141, 3);
assert_eq!(num.abs().to_string(), "3.141");

#[must_use]
pub fn floor(&self) -> Decimal
[src]

Returns the largest integer less than or equal to a number.

Example

use rust_decimal::Decimal;

let num = Decimal::new(3641, 3);
assert_eq!(num.floor().to_string(), "3");

#[must_use]
pub fn ceil(&self) -> Decimal
[src]

Returns the smallest integer greater than or equal to a number.

Example

use rust_decimal::Decimal;

let num = Decimal::new(3141, 3);
assert_eq!(num.ceil().to_string(), "4");
let num = Decimal::new(3, 0);
assert_eq!(num.ceil().to_string(), "3");

#[must_use]
pub fn max(self, other: Decimal) -> Decimal
[src]

Returns the maximum of the two numbers.

use rust_decimal::Decimal;

let x = Decimal::new(1, 0);
let y = Decimal::new(2, 0);
assert_eq!(y, x.max(y));

#[must_use]
pub fn min(self, other: Decimal) -> Decimal
[src]

Returns the minimum of the two numbers.

use rust_decimal::Decimal;

let x = Decimal::new(1, 0);
let y = Decimal::new(2, 0);
assert_eq!(x, x.min(y));

#[must_use]
pub fn normalize(&self) -> Decimal
[src]

Strips any trailing zero’s from a Decimal and converts -0 to 0.

Example

use rust_decimal::prelude::*;

let number = Decimal::from_str("3.100").unwrap();
assert_eq!(number.normalize().to_string(), "3.1");

pub fn normalize_assign(&mut self)[src]

An in place version of normalize. Strips any trailing zero’s from a Decimal and converts -0 to 0.

Example

use rust_decimal::prelude::*;

let mut number = Decimal::from_str("3.100").unwrap();
assert_eq!(number.to_string(), "3.100");
number.normalize_assign();
assert_eq!(number.to_string(), "3.1");

#[must_use]
pub fn round(&self) -> Decimal
[src]

Returns a new Decimal number with no fractional portion (i.e. an integer). Rounding currently follows “Bankers Rounding” rules. e.g. 6.5 -> 6, 7.5 -> 8

Example

use rust_decimal::Decimal;

// Demonstrating bankers rounding...
let number_down = Decimal::new(65, 1);
let number_up   = Decimal::new(75, 1);
assert_eq!(number_down.round().to_string(), "6");
assert_eq!(number_up.round().to_string(), "8");

#[must_use]
pub fn round_dp_with_strategy(
    &self,
    dp: u32,
    strategy: RoundingStrategy
) -> Decimal
[src]

Returns a new Decimal number with the specified number of decimal points for fractional portion. Rounding is performed using the provided RoundingStrategy

Arguments

  • dp: the number of decimal points to round to.
  • strategy: the RoundingStrategy to use.

Example

use rust_decimal::{Decimal, RoundingStrategy};
use core::str::FromStr;

let tax = Decimal::from_str("3.4395").unwrap();
assert_eq!(tax.round_dp_with_strategy(2, RoundingStrategy::MidpointAwayFromZero).to_string(), "3.44");

#[must_use]
pub fn round_dp(&self, dp: u32) -> Decimal
[src]

Returns a new Decimal number with the specified number of decimal points for fractional portion. Rounding currently follows “Bankers Rounding” rules. e.g. 6.5 -> 6, 7.5 -> 8

Arguments

  • dp: the number of decimal points to round to.

Example

use rust_decimal::Decimal;
use core::str::FromStr;

let pi = Decimal::from_str("3.1415926535897932384626433832").unwrap();
assert_eq!(pi.round_dp(2).to_string(), "3.14");

pub const fn unpack(&self) -> UnpackedDecimal[src]

Convert Decimal to an internal representation of the underlying struct. This is useful for debugging the internal state of the object.

Important Disclaimer

This is primarily intended for library maintainers. The internal representation of a Decimal is considered “unstable” for public use.

Example

use rust_decimal::Decimal;
use core::str::FromStr;

let pi = Decimal::from_str("3.1415926535897932384626433832").unwrap();
assert_eq!(format!("{:?}", pi), "3.1415926535897932384626433832");
assert_eq!(format!("{:?}", pi.unpack()), "UnpackedDecimal { \
    negative: false, scale: 28, hi: 1703060790, mid: 185874565, lo: 1102470952 \
}");

#[must_use]
pub fn checked_add(self, other: Decimal) -> Option<Decimal>
[src]

Checked addition. Computes self + other, returning None if overflow occurred.

#[must_use]
pub fn checked_sub(self, other: Decimal) -> Option<Decimal>
[src]

Checked subtraction. Computes self - other, returning None if overflow occurred.

#[must_use]
pub fn checked_mul(self, other: Decimal) -> Option<Decimal>
[src]

Checked multiplication. Computes self * other, returning None if overflow occurred.

#[must_use]
pub fn checked_div(self, other: Decimal) -> Option<Decimal>
[src]

Checked division. Computes self / other, returning None if other == 0.0 or the division results in overflow.

#[must_use]
pub fn checked_rem(self, other: Decimal) -> Option<Decimal>
[src]

Checked remainder. Computes self % other, returning None if other == 0.0.

pub fn from_str_radix(str: &str, radix: u32) -> Result<Self, Error>[src]

Trait Implementations

impl<'a> Add<&'a Decimal> for Decimal[src]

type Output = Decimal

The resulting type after applying the + operator.

fn add(self, other: &Decimal) -> Decimal[src]

Performs the + operation. Read more

impl<'a, 'b> Add<&'b Decimal> for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the + operator.

fn add(self, other: &Decimal) -> Decimal[src]

Performs the + operation. Read more

impl Add<Decimal> for Decimal[src]

type Output = Decimal

The resulting type after applying the + operator.

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

Performs the + operation. Read more

impl<'a> Add<Decimal> for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the + operator.

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

Performs the + operation. Read more

impl<'a> AddAssign<&'a Decimal> for Decimal[src]

fn add_assign(&mut self, other: &'a Decimal)[src]

Performs the += operation. Read more

impl<'a> AddAssign<&'a Decimal> for &'a mut Decimal[src]

fn add_assign(&mut self, other: &'a Decimal)[src]

Performs the += operation. Read more

impl AddAssign<Decimal> for Decimal[src]

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

Performs the += operation. Read more

impl<'a> AddAssign<Decimal> for &'a mut Decimal[src]

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

Performs the += operation. Read more

impl Arbitrary<'_> for Decimal[src]

fn arbitrary(u: &mut Unstructured<'_>) -> ArbitraryResult<Self>[src]

Generate an arbitrary value of Self from the given unstructured data. Read more

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>[src]

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more

fn size_hint(depth: usize) -> (usize, Option<usize>)[src]

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more

impl<'expr> AsExpression<Nullable<Numeric>> for &'expr Decimal[src]

type Expression = Bound<Nullable<Numeric>, Self>

The expression being returned

fn as_expression(self) -> Self::Expression[src]

Perform the conversion

impl AsExpression<Nullable<Numeric>> for Decimal[src]

type Expression = Bound<Nullable<Numeric>, Self>

The expression being returned

fn as_expression(self) -> Self::Expression[src]

Perform the conversion

impl<'expr> AsExpression<Numeric> for &'expr Decimal[src]

type Expression = Bound<Numeric, Self>

The expression being returned

fn as_expression(self) -> Self::Expression[src]

Perform the conversion

impl AsExpression<Numeric> for Decimal[src]

type Expression = Bound<Numeric, Self>

The expression being returned

fn as_expression(self) -> Self::Expression[src]

Perform the conversion

impl CheckedAdd for Decimal[src]

fn checked_add(&self, v: &Decimal) -> Option<Decimal>[src]

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

impl CheckedDiv for Decimal[src]

fn checked_div(&self, v: &Decimal) -> Option<Decimal>[src]

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

impl CheckedMul for Decimal[src]

fn checked_mul(&self, v: &Decimal) -> Option<Decimal>[src]

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

impl CheckedRem for Decimal[src]

fn checked_rem(&self, v: &Decimal) -> Option<Decimal>[src]

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

impl CheckedSub for Decimal[src]

fn checked_sub(&self, v: &Decimal) -> Option<Decimal>[src]

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

impl Clone for Decimal[src]

fn clone(&self) -> Decimal[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 Debug for Decimal[src]

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

Formats the value using the given formatter. Read more

impl Default for Decimal[src]

fn default() -> Self[src]

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

impl<'de> Deserialize<'de> for Decimal[src]

fn deserialize<D>(deserializer: D) -> Result<Decimal, D::Error> where
    D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Display for Decimal[src]

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

Formats the value using the given formatter. Read more

impl<'a> Div<&'a Decimal> for Decimal[src]

type Output = Decimal

The resulting type after applying the / operator.

fn div(self, other: &Decimal) -> Decimal[src]

Performs the / operation. Read more

impl<'a, 'b> Div<&'b Decimal> for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the / operator.

fn div(self, other: &Decimal) -> Decimal[src]

Performs the / operation. Read more

impl Div<Decimal> for Decimal[src]

type Output = Decimal

The resulting type after applying the / operator.

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

Performs the / operation. Read more

impl<'a> Div<Decimal> for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the / operator.

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

Performs the / operation. Read more

impl<'a> DivAssign<&'a Decimal> for Decimal[src]

fn div_assign(&mut self, other: &'a Decimal)[src]

Performs the /= operation. Read more

impl<'a> DivAssign<&'a Decimal> for &'a mut Decimal[src]

fn div_assign(&mut self, other: &'a Decimal)[src]

Performs the /= operation. Read more

impl DivAssign<Decimal> for Decimal[src]

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

Performs the /= operation. Read more

impl<'a> DivAssign<Decimal> for &'a mut Decimal[src]

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

Performs the /= operation. Read more

impl From<i128> for Decimal[src]

fn from(t: i128) -> Self[src]

Performs the conversion.

impl From<i16> for Decimal[src]

fn from(t: i16) -> Self[src]

Performs the conversion.

impl From<i32> for Decimal[src]

fn from(t: i32) -> Self[src]

Performs the conversion.

impl From<i64> for Decimal[src]

fn from(t: i64) -> Self[src]

Performs the conversion.

impl From<i8> for Decimal[src]

fn from(t: i8) -> Self[src]

Performs the conversion.

impl From<isize> for Decimal[src]

fn from(t: isize) -> Self[src]

Performs the conversion.

impl From<u128> for Decimal[src]

fn from(t: u128) -> Self[src]

Performs the conversion.

impl From<u16> for Decimal[src]

fn from(t: u16) -> Self[src]

Performs the conversion.

impl From<u32> for Decimal[src]

fn from(t: u32) -> Self[src]

Performs the conversion.

impl From<u64> for Decimal[src]

fn from(t: u64) -> Self[src]

Performs the conversion.

impl From<u8> for Decimal[src]

fn from(t: u8) -> Self[src]

Performs the conversion.

impl From<usize> for Decimal[src]

fn from(t: usize) -> Self[src]

Performs the conversion.

impl FromPrimitive for Decimal[src]

fn from_i32(n: i32) -> Option<Decimal>[src]

Converts an i32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_i64(n: i64) -> Option<Decimal>[src]

Converts an i64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_i128(n: i128) -> Option<Decimal>[src]

Converts an i128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_u32(n: u32) -> Option<Decimal>[src]

Converts an u32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_u64(n: u64) -> Option<Decimal>[src]

Converts an u64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_u128(n: u128) -> Option<Decimal>[src]

Converts an u128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_f32(n: f32) -> Option<Decimal>[src]

Converts a f32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_f64(n: f64) -> Option<Decimal>[src]

Converts a f64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_isize(n: isize) -> Option<Self>[src]

Converts an isize to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_i8(n: i8) -> Option<Self>[src]

Converts an i8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_i16(n: i16) -> Option<Self>[src]

Converts an i16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_usize(n: usize) -> Option<Self>[src]

Converts a usize to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_u8(n: u8) -> Option<Self>[src]

Converts an u8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

fn from_u16(n: u16) -> Option<Self>[src]

Converts an u16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more

impl<'a> FromSql<'a> for Decimal[src]

fn from_sql(
    _: &Type,
    raw: &[u8]
) -> Result<Decimal, Box<dyn Error + Sync + Send + 'static>>
[src]

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

fn accepts(ty: &Type) -> bool[src]

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

fn from_sql_null(
    ty: &Type
) -> Result<Self, Box<dyn Error + 'static + Sync + Send, Global>>
[src]

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

fn from_sql_nullable(
    ty: &Type,
    raw: Option<&'a [u8]>
) -> Result<Self, Box<dyn Error + 'static + Sync + Send, Global>>
[src]

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

impl FromSql<Numeric, Pg> for Decimal[src]

fn from_sql(numeric: Option<&[u8]>) -> Result<Self>[src]

See the trait documentation.

impl<__ST, __DB> FromSqlRow<__ST, __DB> for Decimal where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

fn build_from_row<R: Row<__DB>>(row: &mut R) -> Result<Self>[src]

See the trait documentation.

const FIELDS_NEEDED: usize[src]

The number of fields that this type will consume. Must be equal to the number of times you would call row.take() in build_from_row Read more

impl FromStr for Decimal[src]

type Err = Error

The associated error which can be returned from parsing.

fn from_str(value: &str) -> Result<Decimal, Self::Err>[src]

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

impl Hash for Decimal[src]

fn hash<H: Hasher>(&self, state: &mut H)[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 LowerExp for Decimal[src]

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

Formats the value using the given formatter.

impl MathematicalOps for Decimal[src]

fn exp(&self) -> Decimal[src]

The estimated exponential function, ex. Stops calculating when it is within tolerance of roughly 0.0000002. Read more

fn checked_exp(&self) -> Option<Decimal>[src]

The estimated exponential function, ex. Stops calculating when it is within tolerance of roughly 0.0000002. Returns None on overflow. Read more

fn exp_with_tolerance(&self, tolerance: Decimal) -> Decimal[src]

The estimated exponential function, ex using the tolerance provided as a hint as to when to stop calculating. A larger tolerance will cause the number to stop calculating sooner at the potential cost of a slightly less accurate result. Read more

fn checked_exp_with_tolerance(&self, tolerance: Decimal) -> Option<Decimal>[src]

The estimated exponential function, ex using the tolerance provided as a hint as to when to stop calculating. A larger tolerance will cause the number to stop calculating sooner at the potential cost of a slightly less accurate result. Returns None on overflow. Read more

fn powi(&self, exp: i64) -> Decimal[src]

Raise self to the given integer exponent: xy

fn checked_powi(&self, exp: i64) -> Option<Decimal>[src]

Raise self to the given integer exponent xy returning None on overflow.

fn powu(&self, exp: u64) -> Decimal[src]

Raise self to the given unsigned integer exponent: xy

fn checked_powu(&self, exp: u64) -> Option<Decimal>[src]

Raise self to the given unsigned integer exponent xy returning None on overflow.

fn powf(&self, exp: f64) -> Decimal[src]

Raise self to the given floating point exponent: xy

fn checked_powf(&self, exp: f64) -> Option<Decimal>[src]

Raise self to the given floating point exponent xy returning None on overflow.

fn powd(&self, exp: Decimal) -> Decimal[src]

Raise self to the given Decimal exponent: xy. If exp is not whole then the approximation ey*ln(x) is used. Read more

fn checked_powd(&self, exp: Decimal) -> Option<Decimal>[src]

Raise self to the given Decimal exponent xy returning None on overflow. If exp is not whole then the approximation ey*ln(x) is used. Read more

fn sqrt(&self) -> Option<Decimal>[src]

The square root of a Decimal. Uses a standard Babylonian method.

fn ln(&self) -> Decimal[src]

The natural logarithm for a Decimal. Uses a fast estimation algorithm This is more accurate on larger numbers and less on numbers less than 1. Read more

fn erf(&self) -> Decimal[src]

Abramowitz Approximation of Error Function from wikipedia

fn norm_cdf(&self) -> Decimal[src]

The Cumulative distribution function for a Normal distribution

fn norm_pdf(&self) -> Decimal[src]

The Probability density function for a Normal distribution.

fn checked_norm_pdf(&self) -> Option<Decimal>[src]

The Probability density function for a Normal distribution returning None on overflow.

impl<'a> Mul<&'a Decimal> for Decimal[src]

type Output = Decimal

The resulting type after applying the * operator.

fn mul(self, other: &Decimal) -> Decimal[src]

Performs the * operation. Read more

impl<'a, 'b> Mul<&'b Decimal> for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the * operator.

fn mul(self, other: &Decimal) -> Decimal[src]

Performs the * operation. Read more

impl Mul<Decimal> for Decimal[src]

type Output = Decimal

The resulting type after applying the * operator.

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

Performs the * operation. Read more

impl<'a> Mul<Decimal> for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the * operator.

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

Performs the * operation. Read more

impl<'a> MulAssign<&'a Decimal> for Decimal[src]

fn mul_assign(&mut self, other: &'a Decimal)[src]

Performs the *= operation. Read more

impl<'a> MulAssign<&'a Decimal> for &'a mut Decimal[src]

fn mul_assign(&mut self, other: &'a Decimal)[src]

Performs the *= operation. Read more

impl MulAssign<Decimal> for Decimal[src]

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

Performs the *= operation. Read more

impl<'a> MulAssign<Decimal> for &'a mut Decimal[src]

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

Performs the *= operation. Read more

impl Neg for Decimal[src]

type Output = Decimal

The resulting type after applying the - operator.

fn neg(self) -> Decimal[src]

Performs the unary - operation. Read more

impl<'a> Neg for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the - operator.

fn neg(self) -> Decimal[src]

Performs the unary - operation. Read more

impl Num for Decimal[src]

type FromStrRadixErr = Error

fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>[src]

Convert from a string and radix (typically 2..=36). Read more

impl One for Decimal[src]

fn one() -> Decimal[src]

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

fn set_one(&mut self)[src]

Sets self to the multiplicative identity element of Self, 1.

fn is_one(&self) -> bool where
    Self: PartialEq<Self>, 
[src]

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

impl Ord for Decimal[src]

fn cmp(&self, other: &Decimal) -> 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 PartialEq<Decimal> for Decimal[src]

fn eq(&self, other: &Decimal) -> 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 PartialOrd<Decimal> for Decimal[src]

fn partial_cmp(&self, other: &Decimal) -> 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 Pow<Decimal> for Decimal[src]

type Output = Decimal

The result after applying the operator.

fn pow(self, rhs: Decimal) -> Self::Output[src]

Returns self to the power rhs. Read more

impl Pow<f64> for Decimal[src]

type Output = Decimal

The result after applying the operator.

fn pow(self, rhs: f64) -> Self::Output[src]

Returns self to the power rhs. Read more

impl Pow<i64> for Decimal[src]

type Output = Decimal

The result after applying the operator.

fn pow(self, rhs: i64) -> Self::Output[src]

Returns self to the power rhs. Read more

impl Pow<u64> for Decimal[src]

type Output = Decimal

The result after applying the operator.

fn pow(self, rhs: u64) -> Self::Output[src]

Returns self to the power rhs. Read more

impl<__ST, __DB> Queryable<__ST, __DB> for Decimal where
    __DB: Backend,
    Self: FromSql<__ST, __DB>, 
[src]

type Row = Self

The Rust type you’d like to map from. Read more

fn build(row: Self::Row) -> Self[src]

Construct an instance of this type

impl<'a> Rem<&'a Decimal> for Decimal[src]

type Output = Decimal

The resulting type after applying the % operator.

fn rem(self, other: &Decimal) -> Decimal[src]

Performs the % operation. Read more

impl<'a, 'b> Rem<&'b Decimal> for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the % operator.

fn rem(self, other: &Decimal) -> Decimal[src]

Performs the % operation. Read more

impl Rem<Decimal> for Decimal[src]

type Output = Decimal

The resulting type after applying the % operator.

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

Performs the % operation. Read more

impl<'a> Rem<Decimal> for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the % operator.

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

Performs the % operation. Read more

impl<'a> RemAssign<&'a Decimal> for Decimal[src]

fn rem_assign(&mut self, other: &'a Decimal)[src]

Performs the %= operation. Read more

impl<'a> RemAssign<&'a Decimal> for &'a mut Decimal[src]

fn rem_assign(&mut self, other: &'a Decimal)[src]

Performs the %= operation. Read more

impl RemAssign<Decimal> for Decimal[src]

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

Performs the %= operation. Read more

impl<'a> RemAssign<Decimal> for &'a mut Decimal[src]

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

Performs the %= operation. Read more

impl Serialize for Decimal[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 Signed for Decimal[src]

fn abs(&self) -> Self[src]

Computes the absolute value. Read more

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

The positive difference of two numbers. Read more

fn signum(&self) -> Self[src]

Returns the sign of the number. Read more

fn is_positive(&self) -> bool[src]

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

fn is_negative(&self) -> bool[src]

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

impl<'a> Sub<&'a Decimal> for Decimal[src]

type Output = Decimal

The resulting type after applying the - operator.

fn sub(self, other: &Decimal) -> Decimal[src]

Performs the - operation. Read more

impl<'a, 'b> Sub<&'b Decimal> for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the - operator.

fn sub(self, other: &Decimal) -> Decimal[src]

Performs the - operation. Read more

impl Sub<Decimal> for Decimal[src]

type Output = Decimal

The resulting type after applying the - operator.

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

Performs the - operation. Read more

impl<'a> Sub<Decimal> for &'a Decimal[src]

type Output = Decimal

The resulting type after applying the - operator.

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

Performs the - operation. Read more

impl<'a> SubAssign<&'a Decimal> for Decimal[src]

fn sub_assign(&mut self, other: &'a Decimal)[src]

Performs the -= operation. Read more

impl<'a> SubAssign<&'a Decimal> for &'a mut Decimal[src]

fn sub_assign(&mut self, other: &'a Decimal)[src]

Performs the -= operation. Read more

impl SubAssign<Decimal> for Decimal[src]

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

Performs the -= operation. Read more

impl<'a> SubAssign<Decimal> for &'a mut Decimal[src]

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

Performs the -= operation. Read more

impl<'a> Sum<&'a Decimal> for Decimal[src]

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

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

impl Sum<Decimal> for Decimal[src]

fn sum<I: Iterator<Item = Decimal>>(iter: I) -> Self[src]

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

impl ToPrimitive for Decimal[src]

fn to_i64(&self) -> Option<i64>[src]

Converts the value of self to an i64. If the value cannot be represented by an i64, then None is returned. Read more

fn to_i128(&self) -> Option<i128>[src]

Converts the value of self to an i128. If the value cannot be represented by an i128 (i64 under the default implementation), then None is returned. Read more

fn to_u64(&self) -> Option<u64>[src]

Converts the value of self to a u64. If the value cannot be represented by a u64, then None is returned. Read more

fn to_u128(&self) -> Option<u128>[src]

Converts the value of self to a u128. If the value cannot be represented by a u128 (u64 under the default implementation), then None is returned. Read more

fn to_f64(&self) -> Option<f64>[src]

Converts the value of self to an f64. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f64. Read more

fn to_isize(&self) -> Option<isize>[src]

Converts the value of self to an isize. If the value cannot be represented by an isize, then None is returned. Read more

fn to_i8(&self) -> Option<i8>[src]

Converts the value of self to an i8. If the value cannot be represented by an i8, then None is returned. Read more

fn to_i16(&self) -> Option<i16>[src]

Converts the value of self to an i16. If the value cannot be represented by an i16, then None is returned. Read more

fn to_i32(&self) -> Option<i32>[src]

Converts the value of self to an i32. If the value cannot be represented by an i32, then None is returned. Read more

fn to_usize(&self) -> Option<usize>[src]

Converts the value of self to a usize. If the value cannot be represented by a usize, then None is returned. Read more

fn to_u8(&self) -> Option<u8>[src]

Converts the value of self to a u8. If the value cannot be represented by a u8, then None is returned. Read more

fn to_u16(&self) -> Option<u16>[src]

Converts the value of self to a u16. If the value cannot be represented by a u16, then None is returned. Read more

fn to_u32(&self) -> Option<u32>[src]

Converts the value of self to a u32. If the value cannot be represented by a u32, then None is returned. Read more

fn to_f32(&self) -> Option<f32>[src]

Converts the value of self to an f32. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f32. Read more

impl ToSql for Decimal[src]

fn to_sql(
    &self,
    _: &Type,
    out: &mut BytesMut
) -> Result<IsNull, Box<dyn Error + Sync + Send + 'static>>
[src]

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

fn accepts(ty: &Type) -> bool[src]

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

fn to_sql_checked(
    &self,
    ty: &Type,
    out: &mut BytesMut
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
[src]

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

impl<__DB> ToSql<Nullable<Numeric>, __DB> for Decimal where
    __DB: Backend,
    Self: ToSql<Numeric, __DB>, 
[src]

fn to_sql<W: Write>(&self, out: &mut Output<'_, W, __DB>) -> Result[src]

See the trait documentation.

impl ToSql<Numeric, Pg> for Decimal[src]

fn to_sql<W: Write>(&self, out: &mut Output<'_, W, Pg>) -> Result[src]

See the trait documentation.

impl<'a> TryFrom<&'a PgNumeric> for Decimal[src]

type Error = Box<dyn Error + Send + Sync>

The type returned in the event of a conversion error.

fn try_from(numeric: &'a PgNumeric) -> Result<Self>[src]

Performs the conversion.

impl TryFrom<PgNumeric> for Decimal[src]

type Error = Box<dyn Error + Send + Sync>

The type returned in the event of a conversion error.

fn try_from(numeric: PgNumeric) -> Result<Self>[src]

Performs the conversion.

impl TryFrom<f32> for Decimal[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(value: f32) -> Result<Self, Error>[src]

Performs the conversion.

impl TryFrom<f64> for Decimal[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(value: f64) -> Result<Self, Error>[src]

Performs the conversion.

impl UpperExp for Decimal[src]

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

Formats the value using the given formatter.

impl Zero for Decimal[src]

fn zero() -> Decimal[src]

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

fn is_zero(&self) -> bool[src]

Returns true if self is equal to the additive identity.

fn set_zero(&mut self)[src]

Sets self to the additive identity element of Self, 0.

impl Copy for Decimal[src]

impl Eq for Decimal[src]

Auto Trait Implementations

impl RefUnwindSafe for Decimal

impl Send for Decimal

impl Sync for Decimal

impl Unpin for Decimal

impl UnwindSafe for Decimal

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> BorrowToSql for T where
    T: ToSql
[src]

pub fn borrow_to_sql(&self) -> &dyn ToSql[src]

Returns a reference to self as a ToSql trait object.

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

fn into_sql<T>(self) -> Self::Expression where
    Self: AsExpression<T>, 
[src]

Convert self to an expression for Diesel’s query builder. Read more

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
    &'a Self: AsExpression<T>, 
[src]

Convert &self to an expression for Diesel’s query builder. Read more

impl<T> Same<T> for T

type Output = T

Should always be Self

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<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V

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

impl<T> FromSqlOwned for T where
    T: for<'a> FromSql<'a>, 
[src]

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

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

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

impl<T, Rhs, Output> NumOps<Rhs, Output> 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> NumRef for T where
    T: Num + for<'r> NumOps<&'r T, T>, 
[src]

impl<T, Base> RefNum<Base> for T where
    T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>, 
[src]