pub struct DecimalAverager<T: DecimalType> { /* private fields */ }
Expand description

Computes averages for Decimal128/Decimal256 values, checking for overflow

This is needed because different precisions for Decimal128/Decimal256 can store different ranges of values and thus sum/count may not fit in the target type.

For example, the precision is 3, the max of value is 999 and the min value is -999

Implementations§

source§

impl<T: DecimalType> DecimalAverager<T>

source

pub fn try_new( sum_scale: i8, target_precision: u8, target_scale: i8, ) -> Result<Self>

Create a new DecimalAverager:

  • sum_scale: the scale of sum values passed to Self::avg
  • target_precision: the output precision
  • target_scale: the output scale

Errors if the resulting data can not be stored

source

pub fn avg(&self, sum: T::Native, count: T::Native) -> Result<T::Native>

Returns the sum/count as a i128/i256 Decimal128/Decimal256 with target_scale and target_precision and reporting overflow.

  • sum: The total sum value stored as Decimal128 with sum_scale (passed to Self::try_new)
  • count: total count, stored as a i128/i256 (NOT a Decimal128/Decimal256 value)

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<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, 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> Allocation for T
where T: RefUnwindSafe + Send + Sync,