Skip to main content

Value

Enum Value 

Source
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§

§

Null

§

Bool(bool)

§

Number(f64)

§

String(String)

§

Array(Vec<Value>)

§

Object(Object)

Implementations§

Source§

impl Value

Source

pub fn is_null(&self) -> bool

Source

pub fn as_str(&self) -> Option<&str>

Source

pub fn as_f64(&self) -> Option<f64>

Source

pub fn as_bool(&self) -> Option<bool>

Source

pub fn as_array(&self) -> Option<&Vec<Value>>

Source

pub fn as_object(&self) -> Option<&Object>

Source

pub fn get(&self, key: &str) -> Option<&Value>

The value of key when this is an object that has it.

Source

pub fn at(&self, index: usize) -> Option<&Value>

The element at index when this is an array that long.

Source

pub fn type_name(&self) -> &'static str

The JS typeof-style name of the value’s type, for error messages.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Value

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The value as JSON.stringify writes it.

Source§

impl From<&str> for Value

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Object> for Value

Source§

fn from(o: Object) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<Option<T>> for Value

Source§

fn from(v: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(a: Vec<Value>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(n: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(n: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(n: i64) -> Self

Converts to this type from the input type.
Source§

impl OptionalQueryElement for Value

Source§

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.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Value

Source§

impl ZeroValue for Value

Source§

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

Writes the value as the row and the query builder hold it.
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.