1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::fmt::{Debug, Display, Formatter};

use serde::{Deserialize, Serialize};

use xcell_errors::{for_3rd::DataType, XResult};

pub use crate::{
    array::{ArrayDescription, ArrayKind},
    decimal::{DecimalDescription, DecimalKind},
    enumerate::EnumerateDescription,
    integer::{IntegerDescription, IntegerKind},
    string::StringDescription,
    value::{color::ColorDescription, time::TimeDescription},
    vector::VectorDescription,
};
use crate::{BooleanDescription, XCellValue};

mod display;
mod parser;
use serde::de::{MapAccess, Visitor};
use std::any::type_name;
use xcell_errors::for_3rd::{read_map_next_extra, read_map_next_key_lowercase, read_map_next_value};

mod der;
mod ser;

#[derive(Debug, Clone, Default, Serialize)]
pub struct TypeMetaInfo {
    pub boolean: BooleanDescription,
    pub string: StringDescription,
    pub vector: VectorDescription,
}

#[derive(Clone, Serialize, Deserialize)]
pub enum XCellTyped {
    Boolean(Box<BooleanDescription>),
    Integer(Box<IntegerDescription>),
    Decimal(Box<DecimalDescription>),
    String(Box<StringDescription>),
    Time(Box<TimeDescription>),
    Color(Box<ColorDescription>),
    Enumerate(Box<EnumerateDescription>),
    Array(Box<ArrayDescription>),
    Vector(Box<VectorDescription>),
}

impl Default for XCellTyped {
    fn default() -> Self {
        Self::Boolean(Box::default())
    }
}

impl XCellTyped {
    pub fn parse_cell(&self, cell: &DataType) -> XResult<XCellValue> {
        match self {
            XCellTyped::Boolean(typing) => typing.parse_cell(cell),
            XCellTyped::Integer(typing) => typing.parse_cell(cell),
            XCellTyped::Decimal(typing) => typing.parse_cell(cell),
            XCellTyped::String(typing) => typing.parse_cell(cell),
            XCellTyped::Time(typing) => typing.parse_cell(cell),
            XCellTyped::Color(typing) => typing.parse_cell(cell),
            XCellTyped::Enumerate(typing) => typing.parse_cell(cell),
            XCellTyped::Array(typing) => typing.parse_cell(cell),
            XCellTyped::Vector(typing) => typing.parse_cell(cell),
        }
    }
}