Skip to main content

FromValue

Trait FromValue 

Source
pub trait FromValue: Sized {
    // Required method
    fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>;
}
Expand description

Converts a Spanner Value into a Rust type.

Implementations are provided for all standard types like String, primitive integer and float types, decimals, timestamps, dates, vectors, and options for nullable fields.

Required Methods§

Source

fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>

Converts a Spanner value into the target Rust type, using the provided Spanner Type metadata for compatibility checks.

§Errors

Returns a ConvertError if the kind of the value does not match the expected kind, if the value is null but the target type is not optional (e.g., Option<T>), or if parsing or decoding the inner value format fails.

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 FromValue for Date

Source§

fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for OffsetDateTime

Source§

fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for String

Source§

fn from_value(value: &Value, _type: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for SystemTime

Source§

fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for Timestamp

Source§

fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for Value

Converts any Spanner Value into a serde_json::Value using runtime Type metadata.

This enables dynamic deserialization of STRUCT, ARRAY, and nested ARRAY<STRUCT<ARRAY<...>>> columns without requiring predefined Rust types.

§Type mapping

Spanner wire formatJSON output
NullValuenull
BoolValuetrue / false
NumberValue (finite)JSON number
NumberValue (NaN/±Infinity)null (matches SDK’s into_serde_value)
StringValue (standard)JSON string (includes stringified INT64, NUMERIC, Base64 BYTES, TIMESTAMP, DATE)
StringValue (+ TypeCode::Json)Parsed JSON object/array/value
ListValue + TypeCode::StructJSON object (positional → named via metadata)
ListValue + TypeCode::ArrayJSON array
StructValue (named wire format)JSON object

§Known limitations

  • Precision Safety: Types such as INT64, NUMERIC, and temporal types (which Spanner transmits as StringValue on the wire) are preserved as JSON strings. This prevents precision loss (e.g. for integers exceeding $2^{53}-1$ or high-precision decimals) during deserialization.
  • NaN/Infinity → null: Non-finite floats become null since JSON has no representation. Callers cannot distinguish these from genuine SQL NULLs.
  • Duplicate field names: Spanner allows structs with duplicate field names (e.g., unnamed columns). Since JSON objects require unique keys, last-write-wins applies via serde_json::Map::insert.
  • Missing struct metadata: When TypeCode::Struct is indicated but no struct_type metadata is available, positional values are returned as a plain JSON array to avoid silent data loss.
Source§

fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for Vec<u8>

Source§

fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for bool

Source§

fn from_value(value: &Value, _type: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for f32

Source§

fn from_value(value: &Value, _type: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for f64

Source§

fn from_value(value: &Value, _type: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for i32

Source§

fn from_value(value: &Value, _type: &Type) -> Result<Self, ConvertError>

Source§

impl FromValue for i64

Source§

fn from_value(value: &Value, _type: &Type) -> Result<Self, ConvertError>

Source§

impl<T> FromValue for Option<T>
where T: FromValue,

Source§

fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>

Source§

impl<T> FromValue for Vec<T>
where T: FromValue,

Source§

fn from_value(value: &Value, type: &Type) -> Result<Self, ConvertError>

Implementors§

Source§

impl FromValue for Decimal

Source§

impl FromValue for google_cloud_spanner::value::Value