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