qt_json_rs/elements.rs
1use std::collections::HashMap;
2
3/// A JSON Value is the Enum containing a Value. This makes it easy to perform match operations
4/// against it.
5#[derive(Debug)]
6pub enum JsonValue {
7 /// This encapsulates a RUST string.
8 String(String),
9 /// Since JS uses 64Bit floats, we can use them also
10 Number(f64),
11 /// Another JavaScript Object containing a Map of keys and values.
12 Object(Object),
13 /// A JavaScript Array containing a list of values.
14 Array(Vec<JsonValue>),
15 /// The explicit undefined type
16 Undefined,
17 /// A Bool
18 Bool(bool),
19 /// A NULL value
20 Null,
21}
22
23/// A JavaScript Object (i.e. A Map of keys and values where keys are strings)
24#[derive(Debug)]
25pub struct Object {
26 /// The number of elements in the object
27 pub size: u32,
28 /// All extracted values from the Object. This does not include JavaScript specific values
29 /// like prototypes and functions.
30 pub values: HashMap<String, JsonValue>,
31}
32
33/// A spacial value which will be located at the base of a [`QJSONDocument`](struct.QJSONDocument.html)
34#[derive(Debug)]
35pub enum JsonBaseValue {
36 Object(Object),
37 Array(Vec<JsonValue>),
38}
39
40/**
41 * This is the base element of a JSON Document.
42 *
43 * A JSON Document can have either an Array or An Object as a Base
44 */
45#[derive(Debug)]
46pub struct JsonBase {
47 /**
48 * The size of the overall Object (not needed in Rust)
49 */
50 pub size: u32,
51 /**
52 * The number of Elements, this base has.
53 * (Self-explainatory for Object and Array)
54 */
55 pub elements: u32,
56 /**
57 * The value of this json
58 */
59 pub value: JsonBaseValue,
60}