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