connectorx/
utils.rs

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