pub trait ToValue {
// Required method
fn to_value(&self) -> Value;
}Expand description
Converts Rust types to Spanner Value.
This trait is used to encode native Rust types into the generic Value
representation suitable for transmission to Cloud Spanner (such as in query parameters
or mutation values).
Implementations are provided for standard Rust types, mapping them to their appropriate
Spanner values. For example, optional types naturally map to Value::Null when they are None.
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl ToValue for Bytes
impl ToValue for Bytes
Encodes the binary payload as a base64 string matching Spanner’s BYTES wire format.
Source§impl ToValue for OffsetDateTime
Available on crate feature unstable-time only.
impl ToValue for OffsetDateTime
unstable-time only.Source§impl ToValue for Uuid
impl ToValue for Uuid
Formats the UUID as a lowercase hyphenated string matching Spanner’s UUID wire format.
Source§impl ToValue for Value
Encodes a serde_json::Value as a Spanner Value.
impl ToValue for Value
Encodes a serde_json::Value as a Spanner Value.
Formats the JSON document as a standard RFC 7159 JSON string wrapped in a protobuf
string value (string_value), matching the wire encoding expected by Cloud Spanner
for JSON and PG_JSONB columns.
§SQL NULL vs. JSON null
Cloud Spanner distinguishes between a SQL NULL and a JSON null literal (JSON 'null'):
- A JSON
nulldocument is represented byserde_json::Value::Nulland serializes to the string"null"(SELECT JSON 'null' IS NULLevaluates tofalse). - A SQL
NULLis represented byOption::<serde_json::Value>::None, which converts toValue::null.
Source§impl<const N: usize> ToValue for [u8; N]
Encodes a fixed-size byte array as a Spanner Value.
impl<const N: usize> ToValue for [u8; N]
Encodes a fixed-size byte array as a Spanner Value.
Encodes the binary payload as a base64 string matching Spanner’s BYTES wire format.