pub enum Value {
Undefined,
Null,
Bool(bool),
Number(f64),
String(String),
Array(Vec<Value>),
Object(Vec<(String, Value)>),
}Expand description
A parsed value in the fixture data model. See the module notes.
Variants§
Undefined
No value at all: an empty expected cell, or a parse that produced
nothing. Distinct from Value::Null, as in TypeScript.
Null
Bool(bool)
Number(f64)
Every number is an f64, as in the canonical runtime. An integer
beyond 2^53 is therefore inexact here exactly as it is in
JSON.parse, and a fixture must not pin one.
String(String)
Array(Vec<Value>)
Object(Vec<(String, Value)>)
Entries in document order. Order never takes part in equality (ADR-15 keeps key order out of the value contract); it is kept so a failure message renders the value the way the fixture wrote it.
Implementations§
Source§impl Value
impl Value
Sourcepub fn parse_json(text: &str) -> Result<Value, String>
pub fn parse_json(text: &str) -> Result<Value, String>
Read a JSON text. The error is a short reason without the text
itself, so crate::parse_expect can quote the cell once.
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
The entry at key of an object, or None for anything else.
Sourcepub fn insert(&mut self, key: impl Into<String>, value: Value)
pub fn insert(&mut self, key: impl Into<String>, value: Value)
Insert or replace an object entry, keeping the position of an existing key, which is what a JavaScript object does.
Sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Whether this is Value::Undefined.
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Whether this is Value::Null.