xcell_types/typing/
mod.rs1use std::fmt::{Debug, Display, Formatter};
2
3use serde::{Deserialize, Serialize};
4
5use xcell_errors::{for_3rd::DataType, XResult};
6
7pub use crate::{
8 array::{ArrayDescription, ArrayKind},
9 decimal::{DecimalDescription, DecimalKind},
10 enumerate::EnumerateDescription,
11 integer::{IntegerDescription, IntegerKind},
12 string::StringDescription,
13 value::{color::ColorDescription, time::TimeDescription},
14 vector::VectorDescription,
15};
16use crate::{BooleanDescription, XCellValue};
17
18mod display;
19mod parser;
20use serde::de::{MapAccess, Visitor};
21use std::any::type_name;
22use xcell_errors::for_3rd::{read_map_next_extra, read_map_next_key_lowercase, read_map_next_value};
23
24mod der;
25mod ser;
26
27#[derive(Debug, Clone, Default, Serialize)]
28pub struct TypeMetaInfo {
29 pub boolean: BooleanDescription,
30 pub string: StringDescription,
31 pub vector: VectorDescription,
32}
33
34#[derive(Clone, Serialize, Deserialize)]
35pub enum XCellTyped {
36 Boolean(Box<BooleanDescription>),
37 Integer(Box<IntegerDescription>),
38 Decimal(Box<DecimalDescription>),
39 String(Box<StringDescription>),
40 Time(Box<TimeDescription>),
41 Color(Box<ColorDescription>),
42 Enumerate(Box<EnumerateDescription>),
43 Array(Box<ArrayDescription>),
44 Vector(Box<VectorDescription>),
45}
46
47impl Default for XCellTyped {
48 fn default() -> Self {
49 Self::Boolean(Box::default())
50 }
51}
52
53impl XCellTyped {
54 pub fn parse_cell(&self, cell: &DataType) -> XResult<XCellValue> {
55 match self {
56 XCellTyped::Boolean(typing) => typing.parse_cell(cell),
57 XCellTyped::Integer(typing) => typing.parse_cell(cell),
58 XCellTyped::Decimal(typing) => typing.parse_cell(cell),
59 XCellTyped::String(typing) => typing.parse_cell(cell),
60 XCellTyped::Time(typing) => typing.parse_cell(cell),
61 XCellTyped::Color(typing) => typing.parse_cell(cell),
62 XCellTyped::Enumerate(typing) => typing.parse_cell(cell),
63 XCellTyped::Array(typing) => typing.parse_cell(cell),
64 XCellTyped::Vector(typing) => typing.parse_cell(cell),
65 }
66 }
67}