sciforge_parser/json/
value.rs1#[derive(Clone, Copy, Debug, PartialEq)]
2pub enum JsonValue<'a> {
3 Null,
4 Bool(bool),
5 Number(f64),
6 String(&'a str),
7 Array,
8 Object,
9}
10
11impl<'a> JsonValue<'a> {
12 pub const fn is_object(&self) -> bool {
13 matches!(self, JsonValue::Object)
14 }
15
16 pub const fn is_array(&self) -> bool {
17 matches!(self, JsonValue::Array)
18 }
19
20 pub const fn as_str(&self) -> Option<&str> {
21 match self {
22 JsonValue::String(v) => Some(v),
23 _ => None,
24 }
25 }
26
27 pub const fn as_bool(&self) -> Option<bool> {
28 match self {
29 JsonValue::Bool(v) => Some(*v),
30 _ => None,
31 }
32 }
33
34 pub const fn as_number(&self) -> Option<f64> {
35 match self {
36 JsonValue::Number(v) => Some(*v),
37 _ => None,
38 }
39 }
40}