kv3/
value.rs

1use std::fmt::Debug;
2
3use crate::{Header, ObjectKey};
4
5#[derive(Debug, Clone, PartialEq)]
6pub enum Value {
7    File(Header, Box<Value>),
8    Object(Vec<(ObjectKey, Value)>),
9    Array(Vec<Value>),
10    Flag(String, Box<Value>),
11    String(String),
12    Number(f64),
13    Bool(bool),
14    Null,
15}
16
17impl Value {
18    pub fn is_file(&self) -> bool {
19        matches!(self, Value::File(_, _))
20    }
21
22    pub fn is_object(&self) -> bool {
23        matches!(self, Value::Object(_))
24    }
25
26    pub fn is_array(&self) -> bool {
27        matches!(self, Value::Array(_))
28    }
29
30    pub fn is_flag(&self) -> bool {
31        matches!(self, Value::Flag(_, _))
32    }
33
34    pub fn is_string(&self) -> bool {
35        matches!(self, Value::String(_))
36    }
37
38    pub fn is_number(&self) -> bool {
39        matches!(self, Value::Number(_))
40    }
41
42    pub fn is_boolean(&self) -> bool {
43        matches!(self, Value::Bool(_))
44    }
45
46    pub fn is_null(&self) -> bool {
47        matches!(self, Value::Null)
48    }
49}