pub enum Value {
Undefined,
Null,
Bool(bool),
Number(f64),
String(String),
Array(Rc<Vec<Value>>),
Object(Rc<Map>),
}Expand description
A JSON-like value.
Scalars are owned. Array and Object share their contents through Rc
so an unchanged subtree can be returned by pointer.
Variants§
Undefined
JavaScript undefined. Absent root, removal sentinel, or a read-back
sparse hole.
Null
JavaScript null. A real value, treated as a map for type coercion.
Bool(bool)
A boolean.
Number(f64)
A number. Carries the raw f64 so -0.0 and NaN survive.
String(String)
A string.
Array(Rc<Vec<Value>>)
An array. Sparse holes are stored as Undefined, since a JavaScript
hole reads back as undefined.
Object(Rc<Map>)
A map of string keys to values.
Implementations§
Source§impl Value
impl Value
Sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Whether this is Undefined.
Sourcepub fn from_pairs<K, I>(pairs: I) -> Value
pub fn from_pairs<K, I>(pairs: I) -> Value
Build a map value from key and value pairs, in order.
Convenience for tests and call sites that hold literal data.
Sourcepub fn ptr_eq(&self, other: &Value) -> bool
pub fn ptr_eq(&self, other: &Value) -> bool
Pointer equality for shared containers.
Returns true when both values are the same array or the same map by
Rc pointer. This is the structural-sharing check: an untouched
subtree returns its original pointer, so callers can detect “no change”
cheaply. Scalars never share, so this returns false for them.
Sourcepub fn same_value(&self, other: &Value) -> bool
pub fn same_value(&self, other: &Value) -> bool
SameValue equality, the Object.is algorithm.
Numbers follow SameValue: every NaN equals every NaN regardless of
bit pattern, and +0.0 does not equal -0.0. Containers compare by
pointer, which is what the engine’s no-op check needs. This is not deep
equality. Two distinct arrays with equal contents are not SameValue
equal.
Trait Implementations§
Source§impl PartialEq for Value
impl PartialEq for Value
Source§fn eq(&self, other: &Value) -> bool
fn eq(&self, other: &Value) -> bool
Deep value equality.
Numbers follow SameValue, so NaN == NaN holds for any two NaN and
tests can assert on it. This matches same_value on scalars and is
deliberate. Do not switch the Number arm to plain ==, or NaN
assertions break. Arrays and maps compare element by element, which is
where this differs from same_value: two distinct arrays with equal
contents are equal here but not under same_value. This is the equality
assert_eq! uses in tests, not the engine’s no-op check.