FromSpanner

Trait FromSpanner 

Source
pub trait FromSpanner<'a>: Sized {
    // Required method
    fn from_spanner(value: &'a Value) -> Result<Self, Error>;

    // Provided methods
    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 TypeSpanner Type
boolBOOL
u8, i8, u16, i16, u32, i32, i64INT64
f64FLOAT64
&str, StringSTRING
&[u8], BytesBYTES

The following are provided when the corresponding feature is enabled:

FeatureRust TypeSpanner Type
jsonserde_json::ValueJSON
numericbigdecimal::BigDecimalNUMERIC
temporalchrono::DateTime<Utc>TIMESTAMP
temporalchrono::NaiveDateDATE

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

Source

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§

Source

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.

Source

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a> FromSpanner<'a> for &'a Value

Source§

fn from_spanner(value: &'a Value) -> Result<&'a Value, Error>

Source§

impl<'a> FromSpanner<'a> for &'a str

Source§

fn from_spanner(value: &'a Value) -> Result<Self, Error>

Source§

impl<'a> FromSpanner<'a> for &'a BigDecimal

Source§

impl<'a> FromSpanner<'a> for &'a Bytes

Source§

fn from_spanner(value: &'a Value) -> Result<&'a Bytes, Error>

Source§

impl<'a> FromSpanner<'a> for &'a DateTime<Utc>

Source§

impl<'a> FromSpanner<'a> for &'a NaiveDate

Source§

impl<'a> FromSpanner<'a> for &'a [u8]

Source§

fn from_spanner(value: &'a Value) -> Result<&'a [u8], Error>

Source§

impl<'a> FromSpanner<'a> for Value

Source§

impl<'a> FromSpanner<'a> for bool

Source§

impl<'a> FromSpanner<'a> for f64

Source§

impl<'a> FromSpanner<'a> for i8

Source§

impl<'a> FromSpanner<'a> for i16

Source§

impl<'a> FromSpanner<'a> for i32

Source§

impl<'a> FromSpanner<'a> for i64

Source§

impl<'a> FromSpanner<'a> for u8

Source§

impl<'a> FromSpanner<'a> for u16

Source§

impl<'a> FromSpanner<'a> for u32

Source§

impl<'a> FromSpanner<'a> for String

Source§

fn from_spanner(value: &'a Value) -> Result<Self, Error>

Source§

impl<'a> FromSpanner<'a> for BigDecimal

Source§

impl<'a> FromSpanner<'a> for Bytes

Source§

impl<'a> FromSpanner<'a> for DateTime<Utc>

Source§

impl<'a> FromSpanner<'a> for NaiveDate

Source§

impl<'a, T> FromSpanner<'a> for Option<T>
where T: FromSpanner<'a>,

Source§

fn from_spanner(value: &'a Value) -> Result<Self, Error>

Source§

fn from_spanner_null(_tpe: &Type) -> Result<Self, Error>

Source§

impl<'a, T> FromSpanner<'a> for Vec<T>
where T: FromSpanner<'a>,

Source§

fn from_spanner(value: &'a Value) -> Result<Self, Error>

Implementors§