Trait spanner_rs::FromSpanner
source · [−]pub trait FromSpanner<'a>: Sized {
fn from_spanner(value: &'a Value) -> Result<Self, Error>;
fn from_spanner_null(tpe: &Type) -> Result<Self, Error> { ... }
fn from_spanner_nullable(value: &'a Value) -> Result<Self, Error> { ... }
}Expand description
A trait for Rust types that can be converted from Cloud Spanner values.
Types
The crate provides the following mapping between Cloud Spanner types and Rust types.
| Rust Type | Spanner Type |
|---|---|
bool | BOOL |
u8, i8, u16, i16, u32, i32, i64 | INT64 |
f64 | FLOAT64 |
&str, String | STRING |
&[u8], Bytes | BYTES |
The following are provided when the corresponding feature is enabled:
| Feature | Rust Type | Spanner Type |
|---|---|---|
json | serde_json::Value | JSON |
numeric | bigdecimal::BigDecimal | NUMERIC |
temporal | chrono::DateTime<Utc> | TIMESTAMP |
temporal | chrono::NaiveDate | DATE |
Nullability
FromSpanner is implemented for Option<T> when T implements FromSpanner.
Option<T> represents a nullable Spanner value.
Arrays
FromSpanner is implemented for Vec<T> when T implements FromSpanner.
Such values map to Spanner’s Array type.
Arrays may contain null values (i.e.: Vec<Option<T>>). Note that Vec<Vec<T>> is not allowed.
Required Methods
sourcefn from_spanner(value: &'a Value) -> Result<Self, Error>
fn from_spanner(value: &'a Value) -> Result<Self, Error>
Creates a new value of this type from the provided Cloud Spanner value.
Values passed to this method should not be Value::Null, if this is not known to be the case, use FromSpanner::from_spanner_nullable instead.
Provided Methods
sourcefn from_spanner_null(tpe: &Type) -> Result<Self, Error>
fn from_spanner_null(tpe: &Type) -> Result<Self, Error>
Creates a new value of this type from the provided Cloud Spanner NULL value’s type.
sourcefn from_spanner_nullable(value: &'a Value) -> Result<Self, Error>
fn from_spanner_nullable(value: &'a Value) -> Result<Self, Error>
Creates a new value of this type from the provided Cloud Spanner value which may or may not be null.
This method will dispatch to either FromSpanner::from_spanner or FromSpanner::from_spanner_null depending
on whether the provided value is NULL.