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
impl Value
Sourcepub fn is_null(&self) -> bool
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());Sourcepub fn as_str(&self) -> Option<&str>
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);Sourcepub fn as_bool(&self) -> Option<bool>
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);Sourcepub fn as_f64(&self) -> Option<f64>
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.
Sourcepub fn as_list(&self) -> Option<&List>
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.
Sourcepub fn into_string(self) -> Option<String>
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);Sourcepub fn into_list(self) -> Option<List>
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<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.
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§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.
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§impl From<OffsetDateTime> for Value
Available on crate feature unstable-time only.
impl From<OffsetDateTime> for Value
unstable-time only.Source§fn from(date_time: OffsetDateTime) -> Self
fn from(date_time: OffsetDateTime) -> Self
Source§impl From<SystemTime> for Value
impl From<SystemTime> for Value
Source§fn from(system_time: SystemTime) -> Self
fn from(system_time: SystemTime) -> Self
Source§impl From<Value> for Value
Converts a serde_json::Value into a Spanner Value.
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§impl<const N: usize> From<[u8; N]> for Value
Converts a fixed-size byte array into a Spanner Value.
impl<const N: usize> From<[u8; N]> for Value
Converts a fixed-size byte array into a Spanner Value.
Source§impl FromValue for Value
impl FromValue for Value
Source§fn from_value(value: &Value, _spanner_type: &Type) -> Result<Self, ConvertError>
fn from_value(value: &Value, _spanner_type: &Type) -> Result<Self, ConvertError>
Type metadata for compatibility checks. Read moreSource§fn from_owned_value(
value: Value,
_spanner_type: &Type,
) -> Result<Self, ConvertError>
fn from_owned_value( value: Value, _spanner_type: &Type, ) -> Result<Self, ConvertError>
Type metadata for compatibility checks. Read moreimpl StructuralPartialEq for Value
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request