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§
Sourcefn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>
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
impl FromValue for Date
fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>
Source§impl FromValue for OffsetDateTime
impl FromValue for OffsetDateTime
fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>
Source§impl FromValue for String
impl FromValue for String
fn from_value(value: &Value, _type: &Type) -> Result<Self, ConvertError>
Source§impl FromValue for SystemTime
impl FromValue for SystemTime
fn from_value(value: &Value, type_: &Type) -> Result<Self, ConvertError>
Source§impl FromValue for Timestamp
impl FromValue for Timestamp
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.
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 format | JSON output |
|---|---|
NullValue | null |
BoolValue | true / 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::Struct | JSON object (positional → named via metadata) |
ListValue + TypeCode::Array | JSON array |
StructValue (named wire format) | JSON object |
§Known limitations
- Precision Safety: Types such as
INT64,NUMERIC, and temporal types (which Spanner transmits asStringValueon 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
nullsince 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::Structis indicated but nostruct_typemetadata is available, positional values are returned as a plain JSON array to avoid silent data loss.