25 lines
633 B
Rust
25 lines
633 B
Rust
/// A JSON document. Objects keep their key order (and duplicates).
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub enum Value {
|
|
Null,
|
|
Bool(bool),
|
|
Number(f64),
|
|
String(String),
|
|
Array(Vec<Value>),
|
|
Object(Vec<(String, Value)>),
|
|
}
|
|
|
|
impl Value {
|
|
/// Human name of the variant, for error messages.
|
|
pub fn kind(&self) -> &'static str {
|
|
match self {
|
|
Value::Null => "null",
|
|
Value::Bool(_) => "boolean",
|
|
Value::Number(_) => "number",
|
|
Value::String(_) => "string",
|
|
Value::Array(_) => "array",
|
|
Value::Object(_) => "object",
|
|
}
|
|
}
|
|
}
|