xcell_types/decimal/
mod.rs1use serde::{Deserialize, Serialize};
2
3use xcell_errors::{
4 for_3rd::{BigDecimal, DataType, FromPrimitive, ToPrimitive},
5 XResult,
6};
7
8use crate::{utils::syntax_error, XCellValue};
9mod kind;
10mod parse_cell;
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub enum DecimalKind {
14 Float32,
15 Float64,
16 Decimal128,
17}
18
19#[derive(Debug, Default, Clone, Serialize, Deserialize)]
20pub struct DecimalDescription {
21 pub kind: DecimalKind,
22 pub min: BigDecimal,
23 pub max: BigDecimal,
24 pub default: BigDecimal,
25}
26
27impl DecimalDescription {
28 pub fn range<A, B>(min: A, max: B) -> Self
29 where
30 A: Into<BigDecimal>,
31 B: Into<BigDecimal>,
32 {
33 Self { kind: Default::default(), min: min.into(), max: max.into(), default: Default::default() }
34 }
35 pub fn clamp<I>(&self, int: I) -> BigDecimal
36 where
37 I: Into<BigDecimal>,
38 {
39 int.into()
40 }
41}