1use anyhow::Result;
2use rust_decimal::Decimal;
3use std::ops::{Deref, DerefMut};
4
5pub struct DummyBox<T>(pub T);
6
7impl<T> Deref for DummyBox<T> {
8 type Target = T;
9
10 fn deref(&self) -> &Self::Target {
11 &self.0
12 }
13}
14
15impl<T> DerefMut for DummyBox<T> {
16 fn deref_mut(&mut self) -> &mut Self::Target {
17 &mut self.0
18 }
19}
20
21pub fn decimal_to_i128(mut v: Decimal, scale: u32) -> Result<i128> {
22 v.rescale(scale);
23
24 let v_scale = v.scale();
25 if v_scale != scale as u32 {
26 return Err(anyhow::anyhow!(
27 "decimal scale is not equal to expected scale, got: {} expected: {}",
28 v_scale,
29 scale
30 ));
31 }
32
33 Ok(v.mantissa())
34}