Skip to main content

toon_validate_core/
value.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5#[serde(untagged)]
6pub enum Value {
7    Null,
8    Bool(bool),
9    Number(f64),
10    String(String),
11    Array(Vec<Value>),
12    Object(HashMap<String, Value>),
13    Table(Table),
14}
15
16#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
17pub struct Table {
18    pub name: String,
19    pub declared_rows: usize,
20    pub rows: Vec<HashMap<String, Value>>,
21}
22
23impl Value {
24    pub fn is_table(&self) -> bool {
25        matches!(self, Value::Table(_))
26    }
27    
28    pub fn as_table(&self) -> Option<&Table> {
29        match self {
30            Value::Table(t) => Some(t),
31            _ => None,
32        }
33    }
34    
35    pub fn as_object(&self) -> Option<&HashMap<String, Value>> {
36        match self {
37            Value::Object(o) => Some(o),
38            _ => None,
39        }
40    }
41}