Skip to main content

Value

Struct Value 

Source
pub struct Value(/* private fields */);
Expand description

Value is a transparent wrapper around a protobuf value. It adds helper methods for accessing the underlying value.

Implementations§

Source§

impl Value

Source

pub fn null() -> Self

Creates a null Value.

Source

pub fn kind(&self) -> Kind

Returns the kind of the value.

Source

pub fn is_null(&self) -> bool

Returns true if the value is null, or false otherwise.

§Example
use google_cloud_spanner::value::Value;

let value = Value::null();
assert!(value.is_null());

let not_null = Value::from("hello");
assert!(!not_null.is_null());
Source

pub fn as_str(&self) -> Option<&str>

Returns the underlying string slice if the value is a string, or None otherwise.

§Example
use google_cloud_spanner::value::Value;

let value = Value::from("hello");
assert_eq!(value.as_str(), Some("hello"));

let number_value = Value::from(42.5);
assert_eq!(number_value.as_str(), None);
Source

pub fn as_bool(&self) -> Option<bool>

Returns the underlying boolean value if the value is a boolean, or None otherwise.

§Example
use google_cloud_spanner::value::Value;

let value = Value::from(true);
assert_eq!(value.as_bool(), Some(true));

let string_value = Value::from("true");
assert_eq!(string_value.as_bool(), None);
Source

pub fn as_f64(&self) -> Option<f64>

Returns the underlying number value as an f64 if the value is a number, or None otherwise.

§Example
use google_cloud_spanner::value::Value;

let value = Value::from(42.5);
assert_eq!(value.as_f64(), Some(42.5));

let string_value = Value::from("42.5");
assert_eq!(string_value.as_f64(), None);
§Non-Finite Floats

Spanner encodes non-finite IEEE 754 floats (NaN, Infinity, and -Infinity) as string values on the wire. Consequently, as_f64() returns None for non-finite floats. To decode floating point values with full IEEE 754 support including NaN and infinity, use Row::get or FromValue.

Source

pub fn as_list(&self) -> Option<&List>

Returns a reference to the underlying List if the value is a list, or None otherwise.

§Example
use google_cloud_spanner::value::Value;

let value = Value::from(vec![1i64, 2i64]);
assert_eq!(value.as_list().map(|list| list.len()), Some(2));

let null_value = Value::null();
assert_eq!(null_value.as_list(), None);
§Spanner SQL STRUCT Representation

Spanner transmits SQL STRUCT values on the wire as positional Lists accompanied by schema metadata. Both ARRAY and STRUCT columns can be inspected via this method.

Source

pub fn into_string(self) -> Option<String>

Consumes the value and returns the underlying String if the value is a string, or None otherwise.

§Example
use google_cloud_spanner::value::Value;

let value = Value::from("hello".to_string());
assert_eq!(value.into_string(), Some("hello".to_string()));

let number_value = Value::from(42.5);
assert_eq!(number_value.into_string(), None);
Source

pub fn into_list(self) -> Option<List>

Consumes the value and returns the underlying List if the value is a list, or None otherwise.

§Example
use google_cloud_spanner::value::{List, Value};

let value = Value::from(vec![1i64, 2i64]);
assert!(value.into_list().is_some());

let null_value = Value::null();
assert_eq!(null_value.into_list(), None);
§Spanner SQL STRUCT Representation

Spanner transmits SQL STRUCT values on the wire as positional Lists accompanied by schema metadata. Both ARRAY and STRUCT columns can be extracted via this method.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Value

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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

Converts a reference to any ToValue type into a Value by calling ToValue::to_value, which copies the referenced data.

Source§

fn from(reference: &T) -> Self

Converts to this type from the input type.
Source§

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

Converts a mutable reference to any ToValue type into a Value by calling ToValue::to_value, which copies the referenced data.

Source§

fn from(reference: &mut T) -> Self

Converts to this type from the input type.
Source§

impl From<()> for Value

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for Value

Converts a Bytes buffer into a Spanner Value.

Source§

fn from(byte_buffer: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<Date> for Value

Source§

fn from(date: Date) -> Self

Converts to this type from the input type.
Source§

impl From<Date> for Value

Available on crate feature unstable-time only.
Source§

fn from(date: TimeDate) -> Self

Converts to this type from the input type.
Source§

impl From<Decimal> for Value

Source§

fn from(d: Decimal) -> Self

Converts to this type from the input type.
Source§

impl From<OffsetDateTime> for Value

Available on crate feature unstable-time only.
Source§

fn from(date_time: OffsetDateTime) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<Option<T>> for Value

Converts an optional type into a Value.

Source§

fn from(opt: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<SystemTime> for Value

Source§

fn from(system_time: SystemTime) -> Self

Converts to this type from the input type.
Source§

impl From<Timestamp> for Value

Source§

fn from(timestamp: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl From<Uuid> for Value

Converts a Uuid into a Spanner Value.

Source§

fn from(uuid: Uuid) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Converts a serde_json::Value into 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.

Source§

fn from(json: JsonValue) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Value>> From<Vec<T>> for Value

Converts a vector of values into a List Value.

Source§

fn from(v: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for Value

Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<[u8; N]> for Value

Converts a fixed-size byte array into a Spanner Value.

Source§

fn from(bytes_array: [u8; N]) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(float_value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(float_value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(i: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(i: i64) -> Self

Converts to this type from the input type.
Source§

impl FromValue for Value

Source§

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

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

fn from_owned_value( value: Value, _spanner_type: &Type, ) -> Result<Self, ConvertError>

Converts an owned Spanner value into the target Rust type, using the provided Spanner Type metadata for compatibility checks. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Value

Source§

impl ToValue for Value

Source§

fn to_value(&self) -> Value

Encodes this Rust type as a Spanner Value. Read more

Auto Trait Implementations§

§

impl Forget for Value

§

impl Freeze for Value

§

impl Move for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more