pub enum Value {
Null,
Bool(bool),
Number(f64),
String(String),
Array(Vec<Value>),
Object(Object),
}Expand description
A JSON value, the data model Zero syncs and stores.
Numbers are f64, as they are in JS: integers are exact up to 2^53.
Objects are Objects, which keep their keys in JS property order.
Rust strings compare by code point, which for valid strings is the same
as comparing by UTF-16 code unit, as JS === does. A Rust String can’t
hold a lone surrogate, which a JS string can (see rust/PARITY.md).
Variants§
Implementations§
Source§impl Value
impl Value
pub fn is_null(&self) -> bool
pub fn as_str(&self) -> Option<&str>
pub fn as_f64(&self) -> Option<f64>
pub fn as_bool(&self) -> Option<bool>
pub fn as_array(&self) -> Option<&Vec<Value>>
pub fn as_object(&self) -> Option<&Object>
Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
The value of key when this is an object that has it.
Trait Implementations§
Source§impl OptionalQueryElement for Value
impl OptionalQueryElement for Value
Source§fn optional_from_view(view: &ViewValue) -> Result<Option<Self>, ZeroValueError>
fn optional_from_view(view: &ViewValue) -> Result<Option<Self>, ZeroValueError>
Reads the query’s result from its view:
None for no row, or for an
aggregate over no rows.impl StructuralPartialEq for Value
Source§impl ZeroValue for Value
impl ZeroValue for Value
Source§fn from_zero_value(value: &Value) -> Result<Self, ZeroValueError>
fn from_zero_value(value: &Value) -> Result<Self, ZeroValueError>
Reads a value from a row; a missing column reads as
null.Source§fn to_zero_value(&self) -> Value
fn to_zero_value(&self) -> Value
Writes the value as the row and the query builder hold it.
Source§fn value_for_null() -> Option<Self>
fn value_for_null() -> Option<Self>
What a row’s
null reads as when the schema says the column can’t
be null; None to fail. Databases drift from schemas, and JS shows
such a row with the null rather than failing, so strings, numbers,
and booleans read as "", 0, and false. Declare the column
optional() to read the null.Auto Trait Implementations§
impl Forget for Value
impl Freeze for Value
impl Move for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnsafeUnpin for Value
impl UnwindSafe for Value
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more