Skip to main content

ToValue

Trait ToValue 

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

Source

fn to_value(&self) -> Value

Encodes this Rust type as a Spanner Value.

Implementations are responsible for using the correct value kind for the corresponding data type in Spanner.

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 ()

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for Bytes

Encodes a Bytes buffer as a Spanner Value.

Encodes the binary payload as a base64 string matching Spanner’s BYTES wire format.

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for Date

Available on crate feature unstable-time only.
Source§

fn to_value(&self) -> Value

Source§

impl ToValue for OffsetDateTime

Available on crate feature unstable-time only.
Source§

fn to_value(&self) -> Value

Source§

impl ToValue for String

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for SystemTime

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for Uuid

Encodes a Uuid as a Spanner Value.

Formats the UUID as a lowercase hyphenated string matching Spanner’s UUID wire format.

Source§

fn to_value(&self) -> Value

Source§

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 null document is represented by serde_json::Value::Null and serializes to the string "null" (SELECT JSON 'null' IS NULL evaluates to false).
  • A SQL NULL is represented by Option::<serde_json::Value>::None, which converts to Value::null.
Source§

fn to_value(&self) -> Value

Source§

impl ToValue for Vec<u8>

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for [u8]

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for bool

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for f32

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for f64

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for i32

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for i64

Source§

fn to_value(&self) -> Value

Source§

impl ToValue for str

Source§

fn to_value(&self) -> Value

Source§

impl<T: ToValue + ?Sized> ToValue for &T

Encodes a shared reference to a ToValue type as a Spanner Value.

Source§

fn to_value(&self) -> Value

Source§

impl<T: ToValue + ?Sized> ToValue for &mut T

Encodes a mutable reference to a ToValue type as a Spanner Value.

Source§

fn to_value(&self) -> Value

Source§

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

Source§

fn to_value(&self) -> Value

Source§

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

Source§

fn to_value(&self) -> Value

Source§

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.

Source§

fn to_value(&self) -> Value

Implementors§

Source§

impl ToValue for google_cloud_spanner::value::Date

Source§

impl ToValue for Decimal

Source§

impl ToValue for Timestamp

Source§

impl ToValue for google_cloud_spanner::value::Value