#[repr(C)]pub struct Decimal { /* private fields */ }
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§
Source§impl Decimal
impl Decimal
Sourcepub const MIN: Decimal = MIN
pub const MIN: Decimal = MIN
The smallest value that can be represented by this decimal type.
§Examples
Basic usage:
assert_eq!(Decimal::MIN, dec!(-79_228_162_514_264_337_593_543_950_335));
Sourcepub const MAX: Decimal = MAX
pub const MAX: Decimal = MAX
The largest value that can be represented by this decimal type.
§Examples
Basic usage:
assert_eq!(Decimal::MAX, dec!(79_228_162_514_264_337_593_543_950_335));
Sourcepub const NEGATIVE_ONE: Decimal = NEGATIVE_ONE
pub const NEGATIVE_ONE: Decimal = NEGATIVE_ONE
Sourcepub const ONE_HUNDRED: Decimal = ONE_HUNDRED
pub const ONE_HUNDRED: Decimal = ONE_HUNDRED
Sourcepub const ONE_THOUSAND: Decimal = ONE_THOUSAND
pub const ONE_THOUSAND: Decimal = ONE_THOUSAND
Sourcepub const MAX_SCALE: u32 = 28u32
pub const MAX_SCALE: u32 = 28u32
The maximum supported scale value.
Some operations, such as Self::rescale
may accept larger scale values, but these
operations will result in a final value with a scale no larger than this.
Note that the maximum scale is not the same as the maximum possible numeric precision in base-10.
Sourcepub const PI: Decimal
Available on crate feature maths
only.
pub const PI: Decimal
maths
only.A constant representing π as 3.1415926535897932384626433833
§Examples
Basic usage:
assert_eq!(Decimal::PI, dec!(3.1415926535897932384626433833));
Sourcepub const HALF_PI: Decimal
Available on crate feature maths
only.
pub const HALF_PI: Decimal
maths
only.A constant representing π/2 as 1.5707963267948966192313216916
§Examples
Basic usage:
assert_eq!(Decimal::HALF_PI, dec!(1.5707963267948966192313216916));
Sourcepub const QUARTER_PI: Decimal
Available on crate feature maths
only.
pub const QUARTER_PI: Decimal
maths
only.A constant representing π/4 as 0.7853981633974483096156608458
§Examples
Basic usage:
assert_eq!(Decimal::QUARTER_PI, dec!(0.7853981633974483096156608458));
Sourcepub const TWO_PI: Decimal
Available on crate feature maths
only.
pub const TWO_PI: Decimal
maths
only.A constant representing 2π as 6.2831853071795864769252867666
§Examples
Basic usage:
assert_eq!(Decimal::TWO_PI, dec!(6.2831853071795864769252867666));
Sourcepub const E: Decimal
Available on crate feature maths
only.
pub const E: Decimal
maths
only.A constant representing Euler’s number (e) as 2.7182818284590452353602874714
§Examples
Basic usage:
assert_eq!(Decimal::E, dec!(2.7182818284590452353602874714));
Sourcepub const E_INVERSE: Decimal
Available on crate feature maths
only.
pub const E_INVERSE: Decimal
maths
only.A constant representing the inverse of Euler’s number (1/e) as 0.3678794411714423215955237702
§Examples
Basic usage:
assert_eq!(Decimal::E_INVERSE, dec!(0.3678794411714423215955237702));
Sourcepub fn new(num: i64, scale: u32) -> Decimal
pub fn new(num: i64, scale: u32) -> Decimal
Returns a Decimal
with a 64 bit m
representation and corresponding e
scale.
§Arguments
num
- An i64 that represents them
portion of the decimal numberscale
- A u32 representing thee
portion of the decimal number.
§Panics
This function panics if scale
is > Self::MAX_SCALE
.
§Example
let pi = Decimal::new(3141, 3);
assert_eq!(pi.to_string(), "3.141");
Sourcepub fn from_i128_with_scale(num: i128, scale: u32) -> Decimal
pub fn from_i128_with_scale(num: i128, scale: u32) -> Decimal
Creates a Decimal
using a 128 bit signed m
representation and corresponding e
scale.
§Arguments
num
- An i128 that represents them
portion of the decimal numberscale
- A u32 representing thee
portion of the decimal number.
§Panics
This function panics if scale
is > Self::MAX_SCALE
or if num
exceeds the maximum
supported 96 bits.
§Example
let pi = Decimal::from_i128_with_scale(3141i128, 3);
assert_eq!(pi.to_string(), "3.141");
Sourcepub const fn try_from_i128_with_scale(num: i128, scale: u32) -> Result<Decimal>
pub const fn try_from_i128_with_scale(num: i128, scale: u32) -> Result<Decimal>
Checked version of Decimal::from_i128_with_scale
. Will return Err
instead
of panicking at run-time.
§Example
let max = Decimal::try_from_i128_with_scale(i128::MAX, u32::MAX);
assert!(max.is_err());
Sourcepub const fn from_parts(
lo: u32,
mid: u32,
hi: u32,
negative: bool,
scale: u32,
) -> Decimal
pub const fn from_parts( lo: u32, mid: u32, hi: u32, negative: bool, scale: u32, ) -> Decimal
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 toSelf::MAX_SCALE
.
§Example
let pi = Decimal::from_parts(1102470952, 185874565, 1703060790, false, 28);
assert_eq!(pi.to_string(), "3.1415926535897932384626433832");
Sourcepub fn from_str_radix(str: &str, radix: u32) -> Result<Self, Error>
pub fn from_str_radix(str: &str, radix: u32) -> Result<Self, Error>
Converts a string slice in a given base to a decimal.
The string is expected to be an optional + sign followed by digits. Digits are a subset of these characters, depending on radix, and will return an error if outside the expected range:
- 0-9
- a-z
- A-Z
§Examples
Basic usage:
assert_eq!(Decimal::from_str_radix("A", 16)?.to_string(), "10");
Sourcepub fn from_str_exact(str: &str) -> Result<Self, Error>
pub fn from_str_exact(str: &str) -> Result<Self, Error>
Parses a string slice into a decimal. If the value underflows and cannot be represented with the given scale then this will return an error.
§Examples
Basic usage:
assert_eq!(Decimal::from_str_exact("0.001")?.to_string(), "0.001");
assert_eq!(Decimal::from_str_exact("0.00000_00000_00000_00000_00000_001")?.to_string(), "0.0000000000000000000000000001");
assert_eq!(Decimal::from_str_exact("0.00000_00000_00000_00000_00000_0001"), Err(Error::Underflow));
Sourcepub const fn scale(&self) -> u32
pub const fn scale(&self) -> u32
Returns the scale of the decimal number, otherwise known as e
.
§Example
let num = Decimal::new(1234, 3);
assert_eq!(num.scale(), 3u32);
Sourcepub const fn mantissa(&self) -> i128
pub const fn mantissa(&self) -> i128
Returns the mantissa of the decimal number.
§Example
let num = dec!(-1.2345678);
assert_eq!(num.mantissa(), -12345678i128);
assert_eq!(num.scale(), 7);
Sourcepub const fn is_zero(&self) -> bool
pub const fn is_zero(&self) -> bool
Returns true if this Decimal number is equivalent to zero.
§Example
let num = Decimal::ZERO;
assert!(num.is_zero());
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if this Decimal number has zero fractional part (is equal to an integer)
§Example
assert_eq!(dec!(5).is_integer(), true);
// Trailing zeros are also ignored
assert_eq!(dec!(5.0000).is_integer(), true);
// If there is a fractional part then it is not an integer
assert_eq!(dec!(5.1).is_integer(), false);
Sourcepub fn set_sign(&mut self, positive: bool)
👎Deprecated since 1.4.0: please use set_sign_positive
instead
pub fn set_sign(&mut self, positive: bool)
set_sign_positive
insteadSourcepub fn set_sign_positive(&mut self, positive: bool)
pub fn set_sign_positive(&mut self, positive: bool)
Sourcepub fn set_sign_negative(&mut self, negative: bool)
pub fn set_sign_negative(&mut self, negative: bool)
Sourcepub fn rescale(&mut self, scale: u32)
pub fn rescale(&mut self, scale: u32)
Modifies the Decimal
towards the desired scale, attempting to do so without changing the
underlying number itself.
Setting the scale to something less then the current Decimal
s scale will
cause the newly created Decimal
to perform rounding using the MidpointAwayFromZero
strategy.
Scales greater than the maximum precision that can be represented by Decimal
will be
automatically rounded to either Self::MAX_SCALE
or the maximum precision that can
be represented with the given mantissa.
§Arguments
scale
: The desired scale to use for the newDecimal
number.
§Example
// Rescaling to a higher scale preserves the value
let mut number = dec!(1.123);
assert_eq!(number.scale(), 3);
number.rescale(6);
assert_eq!(number.to_string(), "1.123000");
assert_eq!(number.scale(), 6);
// Rescaling to a lower scale forces the number to be rounded
let mut number = dec!(1.45);
assert_eq!(number.scale(), 2);
number.rescale(1);
assert_eq!(number.to_string(), "1.5");
assert_eq!(number.scale(), 1);
// This function never fails. Consequently, if a scale is provided that is unable to be
// represented using the given mantissa, then the maximum possible scale is used.
let mut number = dec!(11.76470588235294);
assert_eq!(number.scale(), 14);
number.rescale(28);
// A scale of 28 cannot be represented given this mantissa, however it was able to represent
// a number with a scale of 27
assert_eq!(number.to_string(), "11.764705882352940000000000000");
assert_eq!(number.scale(), 27);
Sourcepub const fn serialize(&self) -> [u8; 16]
pub const fn serialize(&self) -> [u8; 16]
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
Sourcepub fn deserialize(bytes: [u8; 16]) -> Decimal
pub fn deserialize(bytes: [u8; 16]) -> Decimal
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
Sourcepub fn is_negative(&self) -> bool
👎Deprecated since 0.6.3: please use is_sign_negative
instead
pub fn is_negative(&self) -> bool
is_sign_negative
insteadReturns true
if the decimal is negative.
Sourcepub fn is_positive(&self) -> bool
👎Deprecated since 0.6.3: please use is_sign_positive
instead
pub fn is_positive(&self) -> bool
is_sign_positive
insteadReturns true
if the decimal is positive.
Sourcepub const fn is_sign_negative(&self) -> bool
pub const fn is_sign_negative(&self) -> bool
Returns true
if the sign bit of the decimal is negative.
§Example
assert_eq!(true, Decimal::new(-1, 0).is_sign_negative());
assert_eq!(false, Decimal::new(1, 0).is_sign_negative());
Sourcepub const fn is_sign_positive(&self) -> bool
pub const fn is_sign_positive(&self) -> bool
Returns true
if the sign bit of the decimal is positive.
§Example
assert_eq!(false, Decimal::new(-1, 0).is_sign_positive());
assert_eq!(true, Decimal::new(1, 0).is_sign_positive());
Sourcepub const fn min_value() -> Decimal
👎Deprecated since 1.12.0: Use the associated constant Decimal::MIN
pub const fn min_value() -> Decimal
Returns the minimum possible number that Decimal
can represent.
Sourcepub const fn max_value() -> Decimal
👎Deprecated since 1.12.0: Use the associated constant Decimal::MAX
pub const fn max_value() -> Decimal
Returns the maximum possible number that Decimal
can represent.
Sourcepub fn trunc(&self) -> Decimal
pub fn trunc(&self) -> Decimal
Returns a new Decimal
integral with no fractional portion.
This is a true truncation whereby no rounding is performed.
§Example
let pi = dec!(3.141);
assert_eq!(pi.trunc(), dec!(3));
// Negative numbers are similarly truncated without rounding
let neg = dec!(-1.98765);
assert_eq!(neg.trunc(), Decimal::NEGATIVE_ONE);
Sourcepub fn trunc_with_scale(&self, scale: u32) -> Decimal
pub fn trunc_with_scale(&self, scale: u32) -> Decimal
Returns a new Decimal
with the fractional portion delimited by scale
.
This is a true truncation whereby no rounding is performed.
§Example
let pi = dec!(3.141592);
assert_eq!(pi.trunc_with_scale(2), dec!(3.14));
// Negative numbers are similarly truncated without rounding
let neg = dec!(-1.98765);
assert_eq!(neg.trunc_with_scale(1), dec!(-1.9));
Sourcepub fn fract(&self) -> Decimal
pub fn fract(&self) -> Decimal
Returns a new Decimal
representing the fractional portion of the number.
§Example
let pi = Decimal::new(3141, 3);
let fract = Decimal::new(141, 3);
// note that it returns a decimal
assert_eq!(pi.fract(), fract);
Sourcepub fn abs(&self) -> Decimal
pub fn abs(&self) -> Decimal
Computes the absolute value of self
.
§Example
let num = Decimal::new(-3141, 3);
assert_eq!(num.abs().to_string(), "3.141");
Sourcepub fn floor(&self) -> Decimal
pub fn floor(&self) -> Decimal
Returns the largest integer less than or equal to a number.
§Example
let num = Decimal::new(3641, 3);
assert_eq!(num.floor().to_string(), "3");
Sourcepub fn ceil(&self) -> Decimal
pub fn ceil(&self) -> Decimal
Returns the smallest integer greater than or equal to a number.
§Example
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");
Sourcepub fn max(self, other: Decimal) -> Decimal
pub fn max(self, other: Decimal) -> Decimal
Returns the maximum of the two numbers.
let x = Decimal::new(1, 0);
let y = Decimal::new(2, 0);
assert_eq!(y, x.max(y));
Sourcepub fn min(self, other: Decimal) -> Decimal
pub fn min(self, other: Decimal) -> Decimal
Returns the minimum of the two numbers.
let x = Decimal::new(1, 0);
let y = Decimal::new(2, 0);
assert_eq!(x, x.min(y));
Sourcepub fn normalize(&self) -> Decimal
pub fn normalize(&self) -> Decimal
Strips any trailing zero’s from a Decimal
and converts -0 to 0.
§Example
let number = Decimal::from_str("3.100")?;
assert_eq!(number.normalize().to_string(), "3.1");
Sourcepub fn normalize_assign(&mut self)
pub fn normalize_assign(&mut self)
An in place version of normalize
. Strips any trailing zero’s from a Decimal
and converts -0 to 0.
§Example
let mut number = Decimal::from_str("3.100")?;
assert_eq!(number.to_string(), "3.100");
number.normalize_assign();
assert_eq!(number.to_string(), "3.1");
Sourcepub fn round(&self) -> Decimal
pub fn round(&self) -> Decimal
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
// 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");
Sourcepub fn round_dp_with_strategy(
&self,
dp: u32,
strategy: RoundingStrategy,
) -> Decimal
pub fn round_dp_with_strategy( &self, dp: u32, strategy: RoundingStrategy, ) -> Decimal
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
: theRoundingStrategy
to use.
§Example
let tax = dec!(3.4395);
assert_eq!(tax.round_dp_with_strategy(2, RoundingStrategy::MidpointAwayFromZero).to_string(), "3.44");
Sourcepub fn round_dp(&self, dp: u32) -> Decimal
pub fn round_dp(&self, dp: u32) -> Decimal
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
let pi = dec!(3.1415926535897932384626433832);
assert_eq!(pi.round_dp(2).to_string(), "3.14");
Sourcepub fn round_sf(&self, digits: u32) -> Option<Decimal>
pub fn round_sf(&self, digits: u32) -> Option<Decimal>
Returns Some(Decimal)
number rounded to the specified number of significant digits. If
the resulting number is unable to be represented by the Decimal
number then None
will
be returned.
When the number of significant figures of the Decimal
being rounded is greater than the requested
number of significant digits then rounding will be performed using MidpointNearestEven
strategy.
§Arguments
digits
: the number of significant digits to round to.
§Remarks
A significant figure is determined using the following rules:
- Non-zero digits are always significant.
- Zeros between non-zero digits are always significant.
- Leading zeros are never significant.
- Trailing zeros are only significant if the number contains a decimal point.
§Example
let value = dec!(305.459);
assert_eq!(value.round_sf(0), Some(dec!(0)));
assert_eq!(value.round_sf(1), Some(dec!(300)));
assert_eq!(value.round_sf(2), Some(dec!(310)));
assert_eq!(value.round_sf(3), Some(dec!(305)));
assert_eq!(value.round_sf(4), Some(dec!(305.5)));
assert_eq!(value.round_sf(5), Some(dec!(305.46)));
assert_eq!(value.round_sf(6), Some(dec!(305.459)));
assert_eq!(value.round_sf(7), Some(dec!(305.4590)));
assert_eq!(Decimal::MAX.round_sf(1), None);
let value = dec!(0.012301);
assert_eq!(value.round_sf(3), Some(dec!(0.0123)));
Sourcepub fn round_sf_with_strategy(
&self,
digits: u32,
strategy: RoundingStrategy,
) -> Option<Decimal>
pub fn round_sf_with_strategy( &self, digits: u32, strategy: RoundingStrategy, ) -> Option<Decimal>
Returns Some(Decimal)
number rounded to the specified number of significant digits. If
the resulting number is unable to be represented by the Decimal
number then None
will
be returned.
When the number of significant figures of the Decimal
being rounded is greater than the requested
number of significant digits then rounding will be performed using the provided RoundingStrategy.
§Arguments
digits
: the number of significant digits to round to.strategy
: if required, the rounding strategy to use.
§Remarks
A significant figure is determined using the following rules:
- Non-zero digits are always significant.
- Zeros between non-zero digits are always significant.
- Leading zeros are never significant.
- Trailing zeros are only significant if the number contains a decimal point.
§Example
let value = dec!(305.459);
assert_eq!(value.round_sf_with_strategy(0, RoundingStrategy::ToZero), Some(dec!(0)));
assert_eq!(value.round_sf_with_strategy(1, RoundingStrategy::ToZero), Some(dec!(300)));
assert_eq!(value.round_sf_with_strategy(2, RoundingStrategy::ToZero), Some(dec!(300)));
assert_eq!(value.round_sf_with_strategy(3, RoundingStrategy::ToZero), Some(dec!(305)));
assert_eq!(value.round_sf_with_strategy(4, RoundingStrategy::ToZero), Some(dec!(305.4)));
assert_eq!(value.round_sf_with_strategy(5, RoundingStrategy::ToZero), Some(dec!(305.45)));
assert_eq!(value.round_sf_with_strategy(6, RoundingStrategy::ToZero), Some(dec!(305.459)));
assert_eq!(value.round_sf_with_strategy(7, RoundingStrategy::ToZero), Some(dec!(305.4590)));
assert_eq!(Decimal::MAX.round_sf_with_strategy(1, RoundingStrategy::ToZero), Some(dec!(70000000000000000000000000000)));
let value = dec!(0.012301);
assert_eq!(value.round_sf_with_strategy(3, RoundingStrategy::AwayFromZero), Some(dec!(0.0124)));
Sourcepub const fn unpack(&self) -> UnpackedDecimal
pub const fn unpack(&self) -> UnpackedDecimal
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
let pi = dec!(3.1415926535897932384626433832);
assert_eq!(format!("{:?}", pi), "3.1415926535897932384626433832");
assert_eq!(format!("{:?}", pi.unpack()), "UnpackedDecimal { \
negative: false, scale: 28, hi: 1703060790, mid: 185874565, lo: 1102470952 \
}");
Sourcepub fn from_f32_retain(n: f32) -> Option<Self>
pub fn from_f32_retain(n: f32) -> Option<Self>
Parses a 32-bit float into a Decimal number whilst retaining any non-guaranteed precision.
Typically when a float is parsed in Rust Decimal, any excess bits (after ~7.22 decimal points for f32 as per IEEE-754) are removed due to any digits following this are considered an approximation at best. This function bypasses this additional step and retains these excess bits.
§Example
// Usually floats are parsed leveraging float guarantees. i.e. 0.1_f32 => 0.1
assert_eq!("0.1", Decimal::from_f32(0.1_f32).unwrap().to_string());
// Sometimes, we may want to represent the approximation exactly.
assert_eq!("0.100000001490116119384765625", Decimal::from_f32_retain(0.1_f32).unwrap().to_string());
Sourcepub fn from_f64_retain(n: f64) -> Option<Self>
pub fn from_f64_retain(n: f64) -> Option<Self>
Parses a 64-bit float into a Decimal number whilst retaining any non-guaranteed precision.
Typically when a float is parsed in Rust Decimal, any excess bits (after ~15.95 decimal points for f64 as per IEEE-754) are removed due to any digits following this are considered an approximation at best. This function bypasses this additional step and retains these excess bits.
§Example
// Usually floats are parsed leveraging float guarantees. i.e. 0.1_f64 => 0.1
assert_eq!("0.1", Decimal::from_f64(0.1_f64).unwrap().to_string());
// Sometimes, we may want to represent the approximation exactly.
assert_eq!("0.1000000000000000055511151231", Decimal::from_f64_retain(0.1_f64).unwrap().to_string());
Source§impl Decimal
impl Decimal
Sourcepub fn checked_add(self, other: Decimal) -> Option<Decimal>
pub fn checked_add(self, other: Decimal) -> Option<Decimal>
Checked addition. Computes self + other
, returning None
if overflow occurred.
Sourcepub fn saturating_add(self, other: Decimal) -> Decimal
pub fn saturating_add(self, other: Decimal) -> Decimal
Saturating addition. Computes self + other
, saturating at the relevant upper or lower boundary.
Sourcepub fn checked_mul(self, other: Decimal) -> Option<Decimal>
pub fn checked_mul(self, other: Decimal) -> Option<Decimal>
Checked multiplication. Computes self * other
, returning None
if overflow occurred.
Sourcepub fn saturating_mul(self, other: Decimal) -> Decimal
pub fn saturating_mul(self, other: Decimal) -> Decimal
Saturating multiplication. Computes self * other
, saturating at the relevant upper or lower boundary.
Sourcepub fn checked_sub(self, other: Decimal) -> Option<Decimal>
pub fn checked_sub(self, other: Decimal) -> Option<Decimal>
Checked subtraction. Computes self - other
, returning None
if overflow occurred.
Sourcepub fn saturating_sub(self, other: Decimal) -> Decimal
pub fn saturating_sub(self, other: Decimal) -> Decimal
Saturating subtraction. Computes self - other
, saturating at the relevant upper or lower boundary.
Sourcepub fn checked_div(self, other: Decimal) -> Option<Decimal>
pub fn checked_div(self, other: Decimal) -> Option<Decimal>
Checked division. Computes self / other
, returning None
if overflow occurred.
Sourcepub fn checked_rem(self, other: Decimal) -> Option<Decimal>
pub fn checked_rem(self, other: Decimal) -> Option<Decimal>
Checked remainder. Computes self % other
, returning None
if overflow occurred.
Trait Implementations§
Source§impl<'a> AddAssign<&'a Decimal> for &'a mut Decimal
impl<'a> AddAssign<&'a Decimal> for &'a mut Decimal
Source§fn add_assign(&mut self, other: &'a Decimal)
fn add_assign(&mut self, other: &'a Decimal)
+=
operation. Read moreSource§impl<'a> AddAssign<&'a Decimal> for Decimal
impl<'a> AddAssign<&'a Decimal> for Decimal
Source§fn add_assign(&mut self, other: &'a Decimal)
fn add_assign(&mut self, other: &'a Decimal)
+=
operation. Read moreSource§impl AddAssign<Decimal> for &mut Decimal
impl AddAssign<Decimal> for &mut Decimal
Source§fn add_assign(&mut self, other: Decimal)
fn add_assign(&mut self, other: Decimal)
+=
operation. Read moreSource§impl AddAssign for Decimal
impl AddAssign for Decimal
Source§fn add_assign(&mut self, other: Decimal)
fn add_assign(&mut self, other: Decimal)
+=
operation. Read moreSource§impl Arbitrary<'_> for Decimal
Available on crate feature rust-fuzz
only.
impl Arbitrary<'_> for Decimal
rust-fuzz
only.Source§fn arbitrary(u: &mut Unstructured<'_>) -> ArbitraryResult<Self>
fn arbitrary(u: &mut Unstructured<'_>) -> ArbitraryResult<Self>
Self
from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self
from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured
this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured
this type
needs to construct itself. Read moreSource§impl Arbitrary for Decimal
Available on crate feature proptest
only.
impl Arbitrary for Decimal
proptest
only.Source§type Parameters = ()
type Parameters = ()
arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
.Source§type Strategy = Map<(<(u32, u32, u32, bool) as Arbitrary>::Strategy, RangeInclusive<u8>), fn(_: ((u32, u32, u32, bool), u8)) -> Decimal>
type Strategy = Map<(<(u32, u32, u32, bool) as Arbitrary>::Strategy, RangeInclusive<u8>), fn(_: ((u32, u32, u32, bool), u8)) -> Decimal>
Strategy
used to generate values of type Self
.Source§fn arbitrary_with(_parameters: Self::Parameters) -> Self::Strategy
fn arbitrary_with(_parameters: Self::Parameters) -> Self::Strategy
Source§impl Archive for Decimal
impl Archive for Decimal
Source§impl<'__expr> AsExpression<Nullable<Numeric>> for &'__expr Decimal
impl<'__expr> AsExpression<Nullable<Numeric>> for &'__expr Decimal
Source§fn as_expression(self) -> Self::Expression
fn as_expression(self) -> Self::Expression
Source§impl AsExpression<Nullable<Numeric>> for Decimal
impl AsExpression<Nullable<Numeric>> for Decimal
Source§fn as_expression(self) -> Self::Expression
fn as_expression(self) -> Self::Expression
Source§impl<'__expr> AsExpression<Numeric> for &'__expr Decimal
impl<'__expr> AsExpression<Numeric> for &'__expr Decimal
Source§type Expression = Bound<Numeric, &'__expr Decimal>
type Expression = Bound<Numeric, &'__expr Decimal>
Source§fn as_expression(self) -> Self::Expression
fn as_expression(self) -> Self::Expression
Source§impl AsExpression<Numeric> for Decimal
impl AsExpression<Numeric> for Decimal
Source§type Expression = Bound<Numeric, Decimal>
type Expression = Bound<Numeric, Decimal>
Source§fn as_expression(self) -> Self::Expression
fn as_expression(self) -> Self::Expression
Source§impl BorshDeserialize for Decimal
impl BorshDeserialize for Decimal
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSchema for Decimal
impl BorshSchema for Decimal
Source§fn declaration() -> Declaration
fn declaration() -> Declaration
Source§fn add_definitions_recursively(
definitions: &mut BTreeMap<Declaration, Definition>,
)
fn add_definitions_recursively( definitions: &mut BTreeMap<Declaration, Definition>, )
Source§impl BorshSerialize for Decimal
impl BorshSerialize for Decimal
Source§impl CheckedAdd for Decimal
impl CheckedAdd for Decimal
Source§impl CheckedDiv for Decimal
impl CheckedDiv for Decimal
Source§impl CheckedMul for Decimal
impl CheckedMul for Decimal
Source§impl CheckedRem for Decimal
impl CheckedRem for Decimal
Source§impl CheckedSub for Decimal
impl CheckedSub for Decimal
Source§impl<'de> Deserialize<'de> for Decimal
Available on crate feature serde
and (crate features serde-with-str
or serde-with-float
or serde-with-arbitrary-precision
) and crate feature serde-str
and crate feature serde-float
only.
impl<'de> Deserialize<'de> for Decimal
serde
and (crate features serde-with-str
or serde-with-float
or serde-with-arbitrary-precision
) and crate feature serde-str
and crate feature serde-float
only.Source§fn deserialize<D>(deserializer: D) -> Result<Decimal, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Decimal, D::Error>where
D: Deserializer<'de>,
Source§impl Distribution<Decimal> for Standard
Available on crate feature rand
only.
impl Distribution<Decimal> for Standard
rand
only.Source§impl Distribution<Decimal> for StandardUniform
Available on crate feature rand-0_9
only.
impl Distribution<Decimal> for StandardUniform
rand-0_9
only.Source§impl<'a> DivAssign<&'a Decimal> for &'a mut Decimal
impl<'a> DivAssign<&'a Decimal> for &'a mut Decimal
Source§fn div_assign(&mut self, other: &'a Decimal)
fn div_assign(&mut self, other: &'a Decimal)
/=
operation. Read moreSource§impl<'a> DivAssign<&'a Decimal> for Decimal
impl<'a> DivAssign<&'a Decimal> for Decimal
Source§fn div_assign(&mut self, other: &'a Decimal)
fn div_assign(&mut self, other: &'a Decimal)
/=
operation. Read moreSource§impl DivAssign<Decimal> for &mut Decimal
impl DivAssign<Decimal> for &mut Decimal
Source§fn div_assign(&mut self, other: Decimal)
fn div_assign(&mut self, other: Decimal)
/=
operation. Read moreSource§impl DivAssign for Decimal
impl DivAssign for Decimal
Source§fn div_assign(&mut self, other: Decimal)
fn div_assign(&mut self, other: Decimal)
/=
operation. Read moreSource§impl<'a> From<&'a Decimal> for PgNumeric
Available on crate feature db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.
impl<'a> From<&'a Decimal> for PgNumeric
db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.Source§impl From<Decimal> for PgNumeric
Available on crate feature db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.
impl From<Decimal> for PgNumeric
db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.Source§impl<'v> FromFormField<'v> for Decimal
Available on crate feature rocket-traits
only.
impl<'v> FromFormField<'v> for Decimal
rocket-traits
only.Source§impl FromPrimitive for Decimal
impl FromPrimitive for Decimal
Source§fn from_i32(n: i32) -> Option<Decimal>
fn from_i32(n: i32) -> Option<Decimal>
i32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i64(n: i64) -> Option<Decimal>
fn from_i64(n: i64) -> Option<Decimal>
i64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i128(n: i128) -> Option<Decimal>
fn from_i128(n: i128) -> Option<Decimal>
i128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moreSource§fn from_u32(n: u32) -> Option<Decimal>
fn from_u32(n: u32) -> Option<Decimal>
u32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u64(n: u64) -> Option<Decimal>
fn from_u64(n: u64) -> Option<Decimal>
u64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_u128(n: u128) -> Option<Decimal>
fn from_u128(n: u128) -> Option<Decimal>
u128
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moreSource§fn from_f32(n: f32) -> Option<Decimal>
fn from_f32(n: f32) -> Option<Decimal>
f32
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_f64(n: f64) -> Option<Decimal>
fn from_f64(n: f64) -> Option<Decimal>
f64
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned. Read moreSource§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize
to return an optional value of this type. If the
value cannot be represented by this type, then None
is returned.Source§impl<'a> FromSql<'a> for Decimal
Available on (crate features db-postgres
or db-tokio-postgres
) and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.
impl<'a> FromSql<'a> for Decimal
db-postgres
or db-tokio-postgres
) and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.Source§fn from_sql(
_: &Type,
raw: &[u8],
) -> Result<Decimal, Box<dyn Error + Sync + Send + 'static>>
fn from_sql( _: &Type, raw: &[u8], ) -> Result<Decimal, Box<dyn Error + Sync + Send + 'static>>
Type
in its binary format. Read moreSource§fn accepts(ty: &Type) -> bool
fn accepts(ty: &Type) -> bool
Type
.Source§impl FromSql<Numeric, Mysql> for Decimal
Available on crate features db-diesel-mysql
and diesel
only.
impl FromSql<Numeric, Mysql> for Decimal
db-diesel-mysql
and diesel
only.Source§impl FromSql<Numeric, Pg> for Decimal
Available on crate feature db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) and crate feature diesel
only.
impl FromSql<Numeric, Pg> for Decimal
db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) and crate feature diesel
only.Source§impl MathematicalOps for Decimal
Available on crate feature maths
only.
impl MathematicalOps for Decimal
maths
only.Source§fn exp(&self) -> Decimal
fn exp(&self) -> Decimal
0.0000002
.Source§fn checked_exp(&self) -> Option<Decimal>
fn checked_exp(&self) -> Option<Decimal>
0.0000002
. Returns None
on overflow.Source§fn exp_with_tolerance(&self, tolerance: Decimal) -> Decimal
fn exp_with_tolerance(&self, tolerance: Decimal) -> Decimal
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.Source§fn checked_exp_with_tolerance(&self, tolerance: Decimal) -> Option<Decimal>
fn checked_exp_with_tolerance(&self, tolerance: Decimal) -> Option<Decimal>
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.Source§fn checked_powi(&self, exp: i64) -> Option<Decimal>
fn checked_powi(&self, exp: i64) -> Option<Decimal>
None
on overflow.Source§fn checked_powu(&self, exp: u64) -> Option<Decimal>
fn checked_powu(&self, exp: u64) -> Option<Decimal>
None
on overflow.Source§fn checked_powf(&self, exp: f64) -> Option<Decimal>
fn checked_powf(&self, exp: f64) -> Option<Decimal>
None
on overflow.Source§fn powd(&self, exp: Decimal) -> Decimal
fn powd(&self, exp: Decimal) -> Decimal
exp
is not whole then the approximation
ey*ln(x) is used.Source§fn checked_powd(&self, exp: Decimal) -> Option<Decimal>
fn checked_powd(&self, exp: Decimal) -> Option<Decimal>
None
on overflow.
If exp
is not whole then the approximation ey*ln(x) is used.Source§fn sqrt(&self) -> Option<Decimal>
fn sqrt(&self) -> Option<Decimal>
Source§fn ln(&self) -> Decimal
fn ln(&self) -> Decimal
Source§fn checked_ln(&self) -> Option<Decimal>
fn checked_ln(&self) -> Option<Decimal>
None
for negative numbers or zero.Source§fn checked_log10(&self) -> Option<Decimal>
fn checked_log10(&self) -> Option<Decimal>
None
for negative numbers or zero.Source§fn checked_norm_pdf(&self) -> Option<Decimal>
fn checked_norm_pdf(&self) -> Option<Decimal>
None
on overflow.Source§fn checked_sin(&self) -> Option<Decimal>
fn checked_sin(&self) -> Option<Decimal>
Source§fn checked_cos(&self) -> Option<Decimal>
fn checked_cos(&self) -> Option<Decimal>
Source§fn tan(&self) -> Decimal
fn tan(&self) -> Decimal
Source§fn checked_tan(&self) -> Option<Decimal>
fn checked_tan(&self) -> Option<Decimal>
Source§impl<'a> MulAssign<&'a Decimal> for &'a mut Decimal
impl<'a> MulAssign<&'a Decimal> for &'a mut Decimal
Source§fn mul_assign(&mut self, other: &'a Decimal)
fn mul_assign(&mut self, other: &'a Decimal)
*=
operation. Read moreSource§impl<'a> MulAssign<&'a Decimal> for Decimal
impl<'a> MulAssign<&'a Decimal> for Decimal
Source§fn mul_assign(&mut self, other: &'a Decimal)
fn mul_assign(&mut self, other: &'a Decimal)
*=
operation. Read moreSource§impl MulAssign<Decimal> for &mut Decimal
impl MulAssign<Decimal> for &mut Decimal
Source§fn mul_assign(&mut self, other: Decimal)
fn mul_assign(&mut self, other: Decimal)
*=
operation. Read moreSource§impl MulAssign for Decimal
impl MulAssign for Decimal
Source§fn mul_assign(&mut self, other: Decimal)
fn mul_assign(&mut self, other: Decimal)
*=
operation. Read moreSource§impl Num for Decimal
impl Num for Decimal
type FromStrRadixErr = Error
Source§fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
2..=36
). Read moreSource§impl Ord for Decimal
impl Ord for Decimal
Source§impl PartialOrd for Decimal
impl PartialOrd for Decimal
Source§impl<'a> RemAssign<&'a Decimal> for &'a mut Decimal
impl<'a> RemAssign<&'a Decimal> for &'a mut Decimal
Source§fn rem_assign(&mut self, other: &'a Decimal)
fn rem_assign(&mut self, other: &'a Decimal)
%=
operation. Read moreSource§impl<'a> RemAssign<&'a Decimal> for Decimal
impl<'a> RemAssign<&'a Decimal> for Decimal
Source§fn rem_assign(&mut self, other: &'a Decimal)
fn rem_assign(&mut self, other: &'a Decimal)
%=
operation. Read moreSource§impl RemAssign<Decimal> for &mut Decimal
impl RemAssign<Decimal> for &mut Decimal
Source§fn rem_assign(&mut self, other: Decimal)
fn rem_assign(&mut self, other: Decimal)
%=
operation. Read moreSource§impl RemAssign for Decimal
impl RemAssign for Decimal
Source§fn rem_assign(&mut self, other: Decimal)
fn rem_assign(&mut self, other: Decimal)
%=
operation. Read moreSource§impl SampleUniform for Decimal
Available on crate feature rand
only.
impl SampleUniform for Decimal
rand
only.Source§impl SampleUniform for Decimal
Available on crate feature rand-0_9
only.
impl SampleUniform for Decimal
rand-0_9
only.Source§impl Serialize for Decimal
Available on crate feature serde
and (crate features serde-with-str
or serde-with-float
or serde-with-arbitrary-precision
) and crate feature serde-float
and crate feature serde-arbitrary-precision
only.
impl Serialize for Decimal
serde
and (crate features serde-with-str
or serde-with-float
or serde-with-arbitrary-precision
) and crate feature serde-float
and crate feature serde-arbitrary-precision
only.Source§impl Signed for Decimal
impl Signed for Decimal
Source§fn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Source§fn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Source§impl<'a> SubAssign<&'a Decimal> for &'a mut Decimal
impl<'a> SubAssign<&'a Decimal> for &'a mut Decimal
Source§fn sub_assign(&mut self, other: &'a Decimal)
fn sub_assign(&mut self, other: &'a Decimal)
-=
operation. Read moreSource§impl<'a> SubAssign<&'a Decimal> for Decimal
impl<'a> SubAssign<&'a Decimal> for Decimal
Source§fn sub_assign(&mut self, other: &'a Decimal)
fn sub_assign(&mut self, other: &'a Decimal)
-=
operation. Read moreSource§impl SubAssign<Decimal> for &mut Decimal
impl SubAssign<Decimal> for &mut Decimal
Source§fn sub_assign(&mut self, other: Decimal)
fn sub_assign(&mut self, other: Decimal)
-=
operation. Read moreSource§impl SubAssign for Decimal
impl SubAssign for Decimal
Source§fn sub_assign(&mut self, other: Decimal)
fn sub_assign(&mut self, other: Decimal)
-=
operation. Read moreSource§impl ToPrimitive for Decimal
impl ToPrimitive for Decimal
Source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
self
to an i64
. If the value cannot be
represented by an i64
, then None
is returned.Source§fn to_i128(&self) -> Option<i128>
fn to_i128(&self) -> Option<i128>
self
to an i128
. If the value cannot be
represented by an i128
(i64
under the default implementation), then
None
is returned. Read moreSource§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
self
to a u64
. If the value cannot be
represented by a u64
, then None
is returned.Source§fn to_u128(&self) -> Option<u128>
fn to_u128(&self) -> Option<u128>
self
to a u128
. If the value cannot be
represented by a u128
(u64
under the default implementation), then
None
is returned. Read moreSource§fn to_f64(&self) -> Option<f64>
fn to_f64(&self) -> Option<f64>
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 moreSource§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
self
to an isize
. If the value cannot be
represented by an isize
, then None
is returned.Source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
self
to an i8
. If the value cannot be
represented by an i8
, then None
is returned.Source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
self
to an i16
. If the value cannot be
represented by an i16
, then None
is returned.Source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
self
to an i32
. If the value cannot be
represented by an i32
, then None
is returned.Source§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
self
to a usize
. If the value cannot be
represented by a usize
, then None
is returned.Source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
self
to a u8
. If the value cannot be
represented by a u8
, then None
is returned.Source§fn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
self
to a u16
. If the value cannot be
represented by a u16
, then None
is returned.Source§impl ToSql<Numeric, Mysql> for Decimal
Available on crate features db-diesel-mysql
and diesel
only.
impl ToSql<Numeric, Mysql> for Decimal
db-diesel-mysql
and diesel
only.Source§impl ToSql<Numeric, Pg> for Decimal
Available on crate feature db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) and crate feature diesel
only.
impl ToSql<Numeric, Pg> for Decimal
db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) and crate feature diesel
only.Source§impl ToSql for Decimal
Available on (crate features db-postgres
or db-tokio-postgres
) and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.
impl ToSql for Decimal
db-postgres
or db-tokio-postgres
) and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.Source§fn to_sql(
&self,
_: &Type,
out: &mut BytesMut,
) -> Result<IsNull, Box<dyn Error + Sync + Send + 'static>>
fn to_sql( &self, _: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send + 'static>>
self
into the binary format of the specified
Postgres Type
, appending it to out
. Read moreSource§fn accepts(ty: &Type) -> bool
fn accepts(ty: &Type) -> bool
Type
.Source§fn to_sql_checked(
&self,
ty: &Type,
out: &mut BytesMut,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn to_sql_checked( &self, ty: &Type, out: &mut BytesMut, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Source§fn encode_format(&self, _ty: &Type) -> Format
fn encode_format(&self, _ty: &Type) -> Format
Source§impl<'a> TryFrom<&'a PgNumeric> for Decimal
Available on crate feature db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.
impl<'a> TryFrom<&'a PgNumeric> for Decimal
db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.Source§impl TryFrom<&str> for Decimal
Try to convert a &str
into a Decimal
.
impl TryFrom<&str> for Decimal
Try to convert a &str
into a Decimal
.
Can fail if the value is out of range for Decimal
.
Source§impl TryFrom<Decimal> for f32
Try to convert a Decimal
to f32
.
impl TryFrom<Decimal> for f32
Try to convert a Decimal
to f32
.
Can fail if the Decimal
is out of range for f32
.
Source§impl TryFrom<Decimal> for f64
Try to convert a Decimal
to f64
.
impl TryFrom<Decimal> for f64
Try to convert a Decimal
to f64
.
Can fail if the Decimal
is out of range for f64
.
Source§impl TryFrom<Decimal> for i128
Try to convert a Decimal
to i128
by truncating and returning the integer component.
impl TryFrom<Decimal> for i128
Try to convert a Decimal
to i128
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for i128
.
Source§impl TryFrom<Decimal> for i16
Try to convert a Decimal
to i16
by truncating and returning the integer component.
impl TryFrom<Decimal> for i16
Try to convert a Decimal
to i16
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for i16
.
Source§impl TryFrom<Decimal> for i32
Try to convert a Decimal
to i32
by truncating and returning the integer component.
impl TryFrom<Decimal> for i32
Try to convert a Decimal
to i32
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for i32
.
Source§impl TryFrom<Decimal> for i64
Try to convert a Decimal
to i64
by truncating and returning the integer component.
impl TryFrom<Decimal> for i64
Try to convert a Decimal
to i64
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for i64
.
Source§impl TryFrom<Decimal> for i8
Try to convert a Decimal
to i8
by truncating and returning the integer component.
impl TryFrom<Decimal> for i8
Try to convert a Decimal
to i8
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for i8
.
Source§impl TryFrom<Decimal> for isize
Try to convert a Decimal
to isize
by truncating and returning the integer component.
impl TryFrom<Decimal> for isize
Try to convert a Decimal
to isize
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for isize
.
Source§impl TryFrom<Decimal> for u128
Try to convert a Decimal
to u128
by truncating and returning the integer component.
impl TryFrom<Decimal> for u128
Try to convert a Decimal
to u128
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for u128
.
Source§impl TryFrom<Decimal> for u16
Try to convert a Decimal
to u16
by truncating and returning the integer component.
impl TryFrom<Decimal> for u16
Try to convert a Decimal
to u16
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for u16
.
Source§impl TryFrom<Decimal> for u32
Try to convert a Decimal
to u32
by truncating and returning the integer component.
impl TryFrom<Decimal> for u32
Try to convert a Decimal
to u32
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for u32
.
Source§impl TryFrom<Decimal> for u64
Try to convert a Decimal
to u64
by truncating and returning the integer component.
impl TryFrom<Decimal> for u64
Try to convert a Decimal
to u64
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for u64
.
Source§impl TryFrom<Decimal> for u8
Try to convert a Decimal
to u8
by truncating and returning the integer component.
impl TryFrom<Decimal> for u8
Try to convert a Decimal
to u8
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for u8
.
Source§impl TryFrom<Decimal> for usize
Try to convert a Decimal
to usize
by truncating and returning the integer component.
impl TryFrom<Decimal> for usize
Try to convert a Decimal
to usize
by truncating and returning the integer component.
Can fail if the Decimal
is out of range for usize
.
Source§impl TryFrom<PgNumeric> for Decimal
Available on crate feature db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.
impl TryFrom<PgNumeric> for Decimal
db-diesel-postgres
and (crate features db-tokio-postgres
or db-postgres
or db-diesel-postgres
) only.Source§impl TryFrom<f32> for Decimal
Try to convert a f32
into a Decimal
.
impl TryFrom<f32> for Decimal
Try to convert a f32
into a Decimal
.
Can fail if the value is out of range for Decimal
.
Source§impl TryFrom<f64> for Decimal
Try to convert a f64
into a Decimal
.
impl TryFrom<f64> for Decimal
Try to convert a f64
into a Decimal
.
Can fail if the value is out of range for Decimal
.
impl Copy for Decimal
impl Eq for Decimal
impl ScalarOperand for Decimal
ndarray
only.Auto Trait Implementations§
impl Freeze for Decimal
impl RefUnwindSafe for Decimal
impl Send for Decimal
impl Sync for Decimal
impl Unpin for Decimal
impl UnwindSafe for Decimal
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
Source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive
, it may be unsized. Read moreSource§type MetadataResolver = ()
type MetadataResolver = ()
Source§unsafe fn resolve_metadata(
&self,
_: usize,
_: <T as ArchiveUnsized>::MetadataResolver,
_: *mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata,
)
unsafe fn resolve_metadata( &self, _: usize, _: <T as ArchiveUnsized>::MetadataResolver, _: *mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata, )
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> BorrowToSql for Twhere
T: ToSql,
impl<T> BorrowToSql for Twhere
T: ToSql,
Source§fn borrow_to_sql(&self) -> &dyn ToSql
fn borrow_to_sql(&self) -> &dyn ToSql
self
as a ToSql
trait object.Source§impl<T> CallHasher for T
impl<T> CallHasher for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<'v, T> FromForm<'v> for Twhere
T: FromFormField<'v>,
impl<'v, T> FromForm<'v> for Twhere
T: FromFormField<'v>,
Source§fn init(opts: Options) -> <T as FromForm<'v>>::Context
fn init(opts: Options) -> <T as FromForm<'v>>::Context
Self
.Source§fn push_value(ctxt: &mut <T as FromForm<'v>>::Context, field: ValueField<'v>)
fn push_value(ctxt: &mut <T as FromForm<'v>>::Context, field: ValueField<'v>)
field
.Source§fn push_data<'life0, 'life1, 'async_trait>(
ctxt: &'life0 mut FromFieldContext<'v, T>,
field: DataField<'v, 'life1>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'v: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn push_data<'life0, 'life1, 'async_trait>(
ctxt: &'life0 mut FromFieldContext<'v, T>,
field: DataField<'v, 'life1>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'v: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
field
.Source§fn finalize(ctxt: <T as FromForm<'v>>::Context) -> Result<T, Errors<'v>>
fn finalize(ctxt: <T as FromForm<'v>>::Context) -> Result<T, Errors<'v>>
Errors
otherwise.Source§impl<T, ST, DB> FromSqlRow<ST, DB> for Twhere
T: Queryable<ST, DB>,
ST: SqlTypeOrSelectable,
DB: Backend,
<T as Queryable<ST, DB>>::Row: FromStaticSqlRow<ST, DB>,
impl<T, ST, DB> FromSqlRow<ST, DB> for Twhere
T: Queryable<ST, DB>,
ST: SqlTypeOrSelectable,
DB: Backend,
<T as Queryable<ST, DB>>::Row: FromStaticSqlRow<ST, DB>,
Source§impl<T, ST, DB> FromStaticSqlRow<ST, DB> for T
impl<T, ST, DB> FromStaticSqlRow<ST, DB> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self
to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self
to an expression for Diesel’s query builder. Read moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
§Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
§Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting()
due to conflicts with Vec::clear()
.
The clear()
method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
Source§impl<Borrowed> SampleBorrow<Borrowed> for Borrowedwhere
Borrowed: SampleUniform,
impl<Borrowed> SampleBorrow<Borrowed> for Borrowedwhere
Borrowed: SampleUniform,
Source§fn borrow(&self) -> &Borrowed
fn borrow(&self) -> &Borrowed
Borrow::borrow
Source§impl<Borrowed> SampleBorrow<Borrowed> for Borrowedwhere
Borrowed: SampleUniform,
impl<Borrowed> SampleBorrow<Borrowed> for Borrowedwhere
Borrowed: SampleUniform,
Source§fn borrow(&self) -> &Borrowed
fn borrow(&self) -> &Borrowed
Borrow::borrow