Struct bigdecimal::BigDecimalRef
source · pub struct BigDecimalRef<'a> { /* private fields */ }
Expand description
Immutable big-decimal, referencing a borrowed buffer of digits
The non-digit information like scale
and sign
may be changed
on these objects, which otherwise would require cloning the full
digit buffer in the BigDecimal.
Built from full BigDecimal
object using the to_ref()
method.
BigDecimal
not implement AsRef
, so we will reserve the method
as_ref()
for a later time.
May be transformed into full BigDecimal object using the to_owned()
method.
This clones the bigdecimal digits.
BigDecimalRef (or Into<BigDecimalRef>
) should be preferred over
using &BigDecimal
for library functions that need an immutable
reference to a bigdecimal, as it may be much more efficient.
NOTE: Using &BigDecimalRef
is redundant, and not recommended.
§Examples
fn add_one<'a, N: Into<BigDecimalRef<'a>>>(n: N) -> BigDecimal {
n.into() + 1
}
let n: BigDecimal = "123.456".parse().unwrap();
// call via "standard" reference (implements Into)
let m = add_one(&n);
assert_eq!(m, "124.456".parse().unwrap());
// call by negating the reference (fast: no-digit cloning involved)
let m = add_one(n.to_ref().neg());
assert_eq!(m, "-122.456".parse().unwrap());
Implementations§
source§impl BigDecimalRef<'_>
impl BigDecimalRef<'_>
sourcepub fn to_owned(&self) -> BigDecimal
pub fn to_owned(&self) -> BigDecimal
Clone digits to make this reference a full BigDecimal object
sourcepub fn to_owned_with_scale(&self, scale: i64) -> BigDecimal
pub fn to_owned_with_scale(&self, scale: i64) -> BigDecimal
Clone digits, returning BigDecimal with given scale
let n: BigDecimal = "123.45678".parse().unwrap();
let r = n.to_ref();
assert_eq!(r.to_owned_with_scale(5), n.clone());
assert_eq!(r.to_owned_with_scale(0), "123".parse().unwrap());
assert_eq!(r.to_owned_with_scale(-1), "12e1".parse().unwrap());
let x = r.to_owned_with_scale(8);
assert_eq!(&x, &n);
assert_eq!(x.fractional_digit_count(), 8);
sourcepub fn fractional_digit_count(&self) -> i64
pub fn fractional_digit_count(&self) -> i64
Return number of digits ‘right’ of the decimal point (including leading zeros)
sourcepub fn count_digits(&self) -> u64
pub fn count_digits(&self) -> u64
Count total number of decimal digits
sourcepub fn sqrt_with_context(&self, ctx: &Context) -> Option<BigDecimal>
pub fn sqrt_with_context(&self, ctx: &Context) -> Option<BigDecimal>
Take square root of this number
Trait Implementations§
source§impl Add<&i128> for BigDecimalRef<'_>
impl Add<&i128> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<&i16> for BigDecimalRef<'_>
impl Add<&i16> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<&i32> for BigDecimalRef<'_>
impl Add<&i32> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<&i64> for BigDecimalRef<'_>
impl Add<&i64> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<&i8> for BigDecimalRef<'_>
impl Add<&i8> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<&u128> for BigDecimalRef<'_>
impl Add<&u128> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<&u16> for BigDecimalRef<'_>
impl Add<&u16> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<&u32> for BigDecimalRef<'_>
impl Add<&u32> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<&u64> for BigDecimalRef<'_>
impl Add<&u64> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<&u8> for BigDecimalRef<'_>
impl Add<&u8> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<BigDecimal> for BigDecimalRef<'_>
impl Add<BigDecimal> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§fn add(self, rhs: BigDecimal) -> BigDecimal
fn add(self, rhs: BigDecimal) -> BigDecimal
+
operation. Read moresource§impl<'a> Add<BigDecimalRef<'a>> for &BigInt
impl<'a> Add<BigDecimalRef<'a>> for &BigInt
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§fn add(self, rhs: BigDecimalRef<'_>) -> BigDecimal
fn add(self, rhs: BigDecimalRef<'_>) -> BigDecimal
+
operation. Read moresource§impl<'a> Add<BigDecimalRef<'a>> for BigInt
impl<'a> Add<BigDecimalRef<'a>> for BigInt
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§fn add(self, rhs: BigDecimalRef<'_>) -> BigDecimal
fn add(self, rhs: BigDecimalRef<'_>) -> BigDecimal
+
operation. Read moresource§impl Add<BigInt> for BigDecimalRef<'_>
impl Add<BigInt> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl<'a, T: Into<BigDecimalRef<'a>>> Add<T> for BigDecimalRef<'_>
impl<'a, T: Into<BigDecimalRef<'a>>> Add<T> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§fn add(self, rhs: T) -> BigDecimal
fn add(self, rhs: T) -> BigDecimal
+
operation. Read moresource§impl Add<i128> for BigDecimalRef<'_>
impl Add<i128> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<i16> for BigDecimalRef<'_>
impl Add<i16> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<i32> for BigDecimalRef<'_>
impl Add<i32> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<i64> for BigDecimalRef<'_>
impl Add<i64> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<i8> for BigDecimalRef<'_>
impl Add<i8> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<u128> for BigDecimalRef<'_>
impl Add<u128> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<u16> for BigDecimalRef<'_>
impl Add<u16> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<u32> for BigDecimalRef<'_>
impl Add<u32> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<u64> for BigDecimalRef<'_>
impl Add<u64> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl Add<u8> for BigDecimalRef<'_>
impl Add<u8> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
+
operator.source§impl<'a> Clone for BigDecimalRef<'a>
impl<'a> Clone for BigDecimalRef<'a>
source§fn clone(&self) -> BigDecimalRef<'a>
fn clone(&self) -> BigDecimalRef<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for BigDecimalRef<'a>
impl<'a> Debug for BigDecimalRef<'a>
source§impl Display for BigDecimalRef<'_>
impl Display for BigDecimalRef<'_>
source§impl<'a> From<&'a BigDecimal> for BigDecimalRef<'a>
impl<'a> From<&'a BigDecimal> for BigDecimalRef<'a>
source§fn from(n: &'a BigDecimal) -> Self
fn from(n: &'a BigDecimal) -> Self
source§impl<'a> From<&'a BigInt> for BigDecimalRef<'a>
impl<'a> From<&'a BigInt> for BigDecimalRef<'a>
source§impl LowerExp for BigDecimalRef<'_>
impl LowerExp for BigDecimalRef<'_>
source§impl Neg for BigDecimalRef<'_>
impl Neg for BigDecimalRef<'_>
source§impl<'rhs, T> PartialEq<T> for BigDecimalRef<'_>
impl<'rhs, T> PartialEq<T> for BigDecimalRef<'_>
source§impl Sub<BigDecimal> for BigDecimalRef<'_>
impl Sub<BigDecimal> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
-
operator.source§fn sub(self, rhs: BigDecimal) -> BigDecimal
fn sub(self, rhs: BigDecimal) -> BigDecimal
-
operation. Read moresource§impl<'a> Sub<BigDecimalRef<'a>> for &BigInt
impl<'a> Sub<BigDecimalRef<'a>> for &BigInt
§type Output = BigDecimal
type Output = BigDecimal
-
operator.source§fn sub(self, rhs: BigDecimalRef<'a>) -> BigDecimal
fn sub(self, rhs: BigDecimalRef<'a>) -> BigDecimal
-
operation. Read moresource§impl<'a> Sub<BigDecimalRef<'a>> for BigInt
impl<'a> Sub<BigDecimalRef<'a>> for BigInt
§type Output = BigDecimal
type Output = BigDecimal
-
operator.source§fn sub(self, rhs: BigDecimalRef<'a>) -> BigDecimal
fn sub(self, rhs: BigDecimalRef<'a>) -> BigDecimal
-
operation. Read moresource§impl Sub<BigInt> for BigDecimalRef<'_>
impl Sub<BigInt> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
-
operator.source§impl<'a, T: Into<BigDecimalRef<'a>>> Sub<T> for BigDecimalRef<'_>
impl<'a, T: Into<BigDecimalRef<'a>>> Sub<T> for BigDecimalRef<'_>
§type Output = BigDecimal
type Output = BigDecimal
-
operator.source§fn sub(self, rhs: T) -> BigDecimal
fn sub(self, rhs: T) -> BigDecimal
-
operation. Read more