Skip to main content

ZeroValue

Trait ZeroValue 

Source
pub trait ZeroValue: Sized {
    // Required methods
    fn from_zero_value(value: &Value) -> Result<Self, ZeroValueError>;
    fn to_zero_value(&self) -> Value;

    // Provided method
    fn value_for_null() -> Option<Self> { ... }
}
Expand description

A Rust type a column holds. Generated row structs use these for their columns, and the query builder encodes compared values with them.

Required Methods§

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.

Provided Methods§

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ZeroValue for String

Source§

impl ZeroValue for bool

Source§

impl ZeroValue for f64

Source§

impl ZeroValue for i64

For a number() column the codegen config declares an integer: the value must be exact, which every integer up to 2^53 is.

Source§

impl<T: ZeroValue> ZeroValue for Option<T>

An optional column: null reads as None.

Source§

impl<T: ZeroValue> ZeroValue for Vec<T>

The JSON arrays a json() column can hold.

Implementors§