Skip to main content

sora_data/
model.rs

1use std::collections::BTreeMap;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6pub struct ConfigData {
7    pub tables: Vec<TableData>,
8}
9
10#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
11pub struct LocalizationData {
12    pub sources: Vec<LocalizationSourceData>,
13}
14
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct LocalizationSourceData {
17    pub name: String,
18    pub columns: Vec<String>,
19    pub rows: Vec<LocalizationRowData>,
20}
21
22#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23pub struct LocalizationRowData {
24    pub values: BTreeMap<String, String>,
25}
26
27#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
28pub struct TableData {
29    pub name: String,
30    pub rows: Vec<RowData>,
31}
32
33#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
34pub struct RowData {
35    pub values: BTreeMap<String, Value>,
36}
37
38#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
39pub enum Value {
40    Bool(bool),
41    Integer(i64),
42    Float(f64),
43    String(String),
44    List(Vec<Value>),
45    Object(BTreeMap<String, Value>),
46    Null,
47}
48
49impl Value {
50    pub(crate) fn kind_name(&self) -> &'static str {
51        match self {
52            Self::Bool(_) => "bool",
53            Self::Integer(_) => "integer",
54            Self::Float(_) => "float",
55            Self::String(_) => "string",
56            Self::List(_) => "list",
57            Self::Object(_) => "object",
58            Self::Null => "null",
59        }
60    }
61}