sql_builder/value/
with_rust_decimal.rs1use super::*;
2
3type_to_value!(Decimal, Decimal, Decimal(None));
4type_ref_clone_to_value!(Decimal);
5
6impl Value {
7 pub fn is_decimal(&self) -> bool {
8 matches!(self, Self::Decimal(_))
9 }
10
11 pub fn as_ref_decimal(&self) -> Option<&Decimal> {
12 match self {
13 Self::Decimal(v) => v.as_ref(),
14 _ => panic!("not Value::Decimal"),
15 }
16 }
17
18 pub fn decimal_to_f64(&self) -> Option<f64> {
19 use rust_decimal::prelude::ToPrimitive;
20
21 self.as_ref_decimal().map(|d| d.to_f64().unwrap())
22 }
23}