pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
Str(String),
Bytes(Vec<u8>),
Array(Vec<Self>),
Object(Vec<(String, Self)>),
}Expand description
A dynamically-typed value that maps to JSON conceptually but serializes via postcard. Uses Vec<(String, Value)> for objects (not HashMap) to guarantee deterministic serialization.
Variants§
Null
Bool(bool)
Int(i64)
Float(f64)
Str(String)
Bytes(Vec<u8>)
Array(Vec<Self>)
Object(Vec<(String, Self)>)
Implementations§
Source§impl Value
impl Value
pub fn type_name(&self) -> &'static str
pub fn as_bool(&self) -> Option<bool>
pub fn as_int(&self) -> Option<i64>
pub fn as_float(&self) -> Option<f64>
pub fn as_str(&self) -> Option<&str>
pub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_array(&self) -> Option<&[Self]>
Sourcepub fn as_object(&self) -> Option<&[(String, Self)]>
pub fn as_object(&self) -> Option<&[(String, Self)]>
The fields of an object value, in insertion order.
Sourcepub fn get(&self, key: &str) -> Option<&Self>
pub fn get(&self, key: &str) -> Option<&Self>
Look up a key in an object value.
Returns None if this is not an object, or has no such key. Objects are
a Vec of pairs rather than a map (to keep serialization
deterministic), so this is a linear scan — fine for the document-shaped
objects it exists for, not for large ones.
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
True for Value::Null.
Sourcepub fn partial_cmp_numeric(&self, other: &Self) -> Option<Ordering>
pub fn partial_cmp_numeric(&self, other: &Self) -> Option<Ordering>
Compare two Values for ordering (used by query engine range ops). Returns None if the values are not comparable (different types).
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Value
Human-readable rendering, for logs, error messages, and {} in tests.
impl Display for Value
Human-readable rendering, for logs, error messages, and {} in tests.
This is not a serialization format — it is lossy on purpose (Bytes
renders as a length, not its contents) and must not be parsed. Use serde for
round-tripping.
Source§impl<T: Into<Self>> From<Option<T>> for Value
None becomes Value::Null — the document model has no notion of an
absent-but-present field, so an optional field is either null or omitted.
impl<T: Into<Self>> From<Option<T>> for Value
None becomes Value::Null — the document model has no notion of an
absent-but-present field, so an optional field is either null or omitted.