Struct tarantool::decimal::Decimal

source ·
pub struct Decimal { /* private fields */ }
Expand description

A Decimal number implemented using the builtin tarantool api.

Availability

This api is not available in all versions of tarantool. Use tarantool::ffi::has_decimal to check if it is supported in your case. If has_decimal returns false, using any function from this module will result in a panic.

This API is thread-safe unlike the original tarantool decimal API.

Implementations§

source§

impl Decimal

source

pub unsafe fn from_raw(inner: decNumber) -> Self

Initialize a Decimal instance from a raw decNumber struct

Safety

inner must a be valid instance of decNumber struct

source

pub fn zero() -> Self

Return a zero decimal number.

source

pub fn precision(&self) -> i32

Return decimal precision, i.e. the amount of decimal digits in its representation.

source

pub fn scale(&self) -> i32

Return decimal scale, i.e. the number of decimal digits after the decimal separator.

source

pub fn is_int(&self) -> bool

Check if the fractional part of the number is 0

source

pub fn trim(self) -> Self

Remove trailing zeros from the fractional part of a number.

source§

impl Decimal

source

pub fn round(self) -> Self

Round a given decimal to have zero digits after the decimal point.

source

pub fn floor(self) -> Self

Floor a given decimal towards zero to have zero digits after the decimal point.

source

pub fn round_to(self, scale: u8) -> Option<Self>

Round a given decimal to have no more than scale digits after the decimal point. If scale if greater than current self.scale(), return self unchanged. Scale must be in range [0..= ffi::DECIMAL_MAX_DIGITS]. Return None if scale if out of bounds.

source

pub fn floor_to(self, scale: u8) -> Option<Self>

Like Decimal::round but rounds the number towards zero.

source

pub fn rescale(self, scale: u8) -> Option<Self>

Set scale of self to scale. If scale < self.scale(), performs the equivalent of self.round(scale). Otherwise appends a sufficient amount of trailing fractional zeros. Return None if scale < 0 or too big.

source

pub fn abs(self) -> Self

Return the absolute value of the number.

source

pub fn log10(self) -> Option<Self>

Compute logarithm base 10.

source

pub fn ln(self) -> Option<Self>

Compute natural logarithm.

source

pub fn exp(self) -> Option<Self>

Exponentiate self. Return None if the result is out of range.

source

pub fn sqrt(self) -> Option<Self>

Compute square root of self. Return None if the result is imaginary or out of range.

source

pub fn pow(self, pow: impl Into<Self>) -> Option<Self>

Compute self raised to the power of pow. Return None if the result is out of range.

source

pub fn to_i64(self) -> Option<i64>

Convert self to i64. Return None if self is not an integer or the value is out of range.

source

pub fn to_u64(self) -> Option<u64>

Convert self to u64. Return None if self is not an integer or the value is out of range.

source§

impl Decimal

source

pub fn checked_add(self, rhs: impl Into<Self>) -> Option<Self>

source§

impl Decimal

source

pub fn checked_sub(self, rhs: impl Into<Self>) -> Option<Self>

source§

impl Decimal

source

pub fn checked_mul(self, rhs: impl Into<Self>) -> Option<Self>

source§

impl Decimal

source

pub fn checked_div(self, rhs: impl Into<Self>) -> Option<Self>

source§

impl Decimal

source

pub fn checked_rem(self, rhs: impl Into<Self>) -> Option<Self>

Trait Implementations§

source§

impl<T: Into<Decimal>> Add<T> for Decimal

§

type Output = Decimal

The resulting type after applying the + operator.
source§

fn add(self, rhs: T) -> Self

Performs the + operation. Read more
source§

impl<T: Into<Decimal>> AddAssign<T> for Decimal

source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
source§

impl Clone for Decimal

source§

fn clone(&self) -> Decimal

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Decimal

source§

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

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Decimal

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Decimal

String conversions

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: Into<Decimal>> Div<T> for Decimal

§

type Output = Decimal

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self

Performs the / operation. Read more
source§

impl<T: Into<Decimal>> DivAssign<T> for Decimal

source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
source§

impl From<i16> for Decimal

source§

fn from(num: i16) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Decimal

source§

fn from(num: i32) -> Self

Converts to this type from the input type.
source§

impl From<i64> for Decimal

source§

fn from(num: i64) -> Self

Converts to this type from the input type.
source§

impl From<i8> for Decimal

source§

fn from(num: i8) -> Self

Converts to this type from the input type.
source§

impl From<isize> for Decimal

source§

fn from(num: isize) -> Self

Converts to this type from the input type.
source§

impl From<u16> for Decimal

source§

fn from(num: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for Decimal

source§

fn from(num: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for Decimal

source§

fn from(num: u64) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Decimal

source§

fn from(num: u8) -> Self

Converts to this type from the input type.
source§

impl From<usize> for Decimal

source§

fn from(num: usize) -> Self

Converts to this type from the input type.
source§

impl FromStr for Decimal

§

type Err = DecimalFromStrError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

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

impl Hash for Decimal

Hash

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

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

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

impl<L> LuaRead<L> for Decimal
where L: AsLua,

source§

fn lua_read_at_position(lua: L, index: NonZeroI32) -> ReadResult<Self, L>

Reads the data from Lua at a given position.
source§

fn n_values_expected() -> i32

source§

fn lua_read(lua: L) -> Result<Self, (L, WrongType)>

Reads the data from Lua.
source§

fn lua_read_at_maybe_zero_position( lua: L, index: i32 ) -> Result<Self, (L, WrongType)>
where L: AsLua,

source§

impl<T: Into<Decimal>> Mul<T> for Decimal

§

type Output = Decimal

The resulting type after applying the * operator.
source§

fn mul(self, rhs: T) -> Self

Performs the * operation. Read more
source§

impl<T: Into<Decimal>> MulAssign<T> for Decimal

source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
source§

impl Neg for Decimal

§

type Output = Decimal

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl Ord for Decimal

source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<i16> for Decimal

source§

fn eq(&self, other: &i16) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i32> for Decimal

source§

fn eq(&self, other: &i32) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i64> for Decimal

source§

fn eq(&self, other: &i64) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<i8> for Decimal

source§

fn eq(&self, other: &i8) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<isize> for Decimal

source§

fn eq(&self, other: &isize) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u16> for Decimal

source§

fn eq(&self, other: &u16) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u32> for Decimal

source§

fn eq(&self, other: &u32) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u64> for Decimal

source§

fn eq(&self, other: &u64) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<u8> for Decimal

source§

fn eq(&self, other: &u8) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<usize> for Decimal

source§

fn eq(&self, other: &usize) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for Decimal

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Decimal

Cmp

source§

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

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

fn lt(&self, other: &Rhs) -> bool

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

fn le(&self, other: &Rhs) -> bool

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

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl<L: AsLua> Push<L> for Decimal

§

type Err = Void

Error that can happen when pushing a value.
source§

fn push_to_lua(&self, lua: L) -> Result<PushGuard<L>, (Self::Err, L)>

Pushes the value on the top of the stack. Read more
source§

fn push_no_err(&self, lua: L) -> PushGuard<L>
where Self::Err: Into<Void>,

Same as push_to_lua but can only succeed and is only available if Err implements Into<Void>.
source§

impl<L: AsLua> PushInto<L> for Decimal

§

type Err = Void

source§

fn push_into_lua(self, lua: L) -> Result<PushGuard<L>, (Self::Err, L)>

Push the value into lua by value
source§

fn push_into_no_err(self, lua: L) -> PushGuard<L>
where Self: Sized, Self::Err: Into<Void>,

Same as push_into_lua but can only succeed and is only available if Err implements Into<Void>.
source§

impl<T: Into<Decimal>> Rem<T> for Decimal

§

type Output = Decimal

The resulting type after applying the % operator.
source§

fn rem(self, rhs: T) -> Self

Performs the % operation. Read more
source§

impl<T: Into<Decimal>> RemAssign<T> for Decimal

source§

fn rem_assign(&mut self, rhs: T)

Performs the %= operation. Read more
source§

impl Serialize for Decimal

Tuple

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Into<Decimal>> Sub<T> for Decimal

§

type Output = Decimal

The resulting type after applying the - operator.
source§

fn sub(self, rhs: T) -> Self

Performs the - operation. Read more
source§

impl<T: Into<Decimal>> SubAssign<T> for Decimal

source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
source§

impl TryFrom<&CStr> for Decimal

§

type Error = DecimalFromStrError

The type returned in the event of a conversion error.
source§

fn try_from(s: &CStr) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&str> for Decimal

§

type Error = <Decimal as FromStr>::Err

The type returned in the event of a conversion error.
source§

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Decimal<{ ffi::DECNUMUNITS as _ }>> for Decimal

§

type Error = ToDecimalError

The type returned in the event of a conversion error.
source§

fn try_from(inner: Decimal<{ _ }>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Decimal> for i64

§

type Error = DecimalToIntError

The type returned in the event of a conversion error.
source§

fn try_from(dec: Decimal) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Decimal> for isize

§

type Error = DecimalToIntError

The type returned in the event of a conversion error.
source§

fn try_from(dec: Decimal) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Decimal> for u64

§

type Error = DecimalToIntError

The type returned in the event of a conversion error.
source§

fn try_from(dec: Decimal) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Decimal> for usize

§

type Error = DecimalToIntError

The type returned in the event of a conversion error.
source§

fn try_from(dec: Decimal) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<f32> for Decimal

§

type Error = DecimalFromfloatError<f32>

The type returned in the event of a conversion error.
source§

fn try_from(num: f32) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<f64> for Decimal

§

type Error = DecimalFromfloatError<f64>

The type returned in the event of a conversion error.
source§

fn try_from(num: f64) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for Decimal

source§

impl Eq for Decimal

source§

impl<L: AsLua> PushOne<L> for Decimal

source§

impl<L: AsLua> PushOneInto<L> for Decimal

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<'de, T> Decode<'de> for T
where T: Deserialize<'de>,

source§

fn decode(data: &'de [u8]) -> Result<T, Error>

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoClones<(T,)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> IntoClones<(T, T, T, T, T, T, T, T, T, T, T)> for T
where T: Clone,

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T> DecodeOwned for T
where T: for<'de> Decode<'de>,

source§

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

source§

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

source§

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>,