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>
impl<T: DecimalType> DecimalAverager<T>
Sourcepub fn try_new(
sum_scale: i8,
target_precision: u8,
target_scale: i8,
) -> Result<Self>
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 toSelf::avg
- target_precision: the output precision
- target_scale: the output scale
Errors if the resulting data can not be stored
Sourcepub fn avg(&self, sum: T::Native, count: T::Native) -> Result<T::Native>
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§
impl<T> Freeze for DecimalAverager<T>
impl<T> RefUnwindSafe for DecimalAverager<T>
impl<T> Send for DecimalAverager<T>
impl<T> Sync for DecimalAverager<T>
impl<T> Unpin for DecimalAverager<T>
impl<T> UnwindSafe for DecimalAverager<T>
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more