#[non_exhaustive]pub enum Value {
Show 31 variants
Void,
Null,
Bool(bool),
Int8(i8),
Uint8(u8),
Int16(i16),
Uint16(u16),
Int32(i32),
Uint32(u32),
Int64(i64),
Uint64(u64),
Float(f32),
Double(f64),
Date(SystemTime),
DateTime(SystemTime),
Timestamp(SystemTime),
IntervalMicros(SignedInterval),
Date32(SystemTime),
Datetime64(SystemTime),
Timestamp64(SystemTime),
Interval64(SignedInterval),
Bytes(Bytes),
Text(String),
Yson(Bytes),
Json(String),
JsonDocument(String),
Optional(Box<ValueOptional>),
List(Box<ValueList>),
Struct(ValueStruct),
Decimal(YdbDecimal),
Uuid(Uuid),
}Expand description
Internal represent database value for send to or received from database.
That enum will be grow, when add support of new types
§Convert from Value to native types
§Primitive values
§From Value to native types
Convert from Value to primitive rust types do by TryFrom trait Try need because Value can contain any DB value and it can’ check at compile time.
// Simple convert to native type
let v: i16 = Value::Int16(123).try_into()?;
assert_eq!(123 as i16, v);
// Simple types can be extended while convert to native type
let v: i32 = Value::Int16(123).try_into()?;
assert_eq!(123 as i32, v);§From native type to Value
// while convert to Value - value internal type exact same as source type - without auto-extended
// because real target type doesn't known in compile time
let v: Value = (123 as i16).into();
assert_eq!(Value::Int16(123), v);§Possible native convertions
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Void
Null
Bool(bool)
Int8(i8)
Uint8(u8)
Int16(i16)
Uint16(u16)
Int32(i32)
Uint32(u32)
Int64(i64)
Uint64(u64)
Float(f32)
Double(f64)
Date(SystemTime)
Date, day granularity. Wire format: uint32 days since UNIX epoch.
Range: 1970-01-01 .. 2105-12-31.
DateTime(SystemTime)
Datetime, second granularity. Wire format: uint32 seconds since UNIX epoch.
Range: 1970-01-01T00:00:00Z .. 2106-02-07T06:28:15Z.
Timestamp(SystemTime)
Timestamp, microsecond granularity. Wire format: uint64 microseconds since UNIX epoch.
Range: 1970-01-01T00:00:00.000000Z .. 2105-12-31T23:59:59.999999Z.
IntervalMicros(SignedInterval)
Signed duration, microsecond granularity on the YDB wire.
Wire format: int64 microseconds.
YDB range (exclusive): (-MAX_TIMESTAMP, MAX_TIMESTAMP) where
MAX_TIMESTAMP = 86_400_000_000 * 49_673 = 4_291_747_200_000_000 µs;
i.e. valid values are -4_291_747_199_999_999 .. 4_291_747_199_999_999
inclusive (≈ ±136 years). Source:
yql/essentials/public/udf/udf_data_type.h.
Date32(SystemTime)
Signed date, day granularity. Wire format: int32 days from UNIX epoch.
YDB range: -53_375_809 .. 53_375_807 days inclusive (year -144169-01-01 ..
148107-12-31). Source: yql/essentials/public/udf/udf_data_type.h.
On Windows, SystemTime cannot represent dates before 1601-01-01.
Datetime64(SystemTime)
Signed datetime, second granularity. Wire format: int64 seconds from UNIX epoch.
YDB range: -4_611_669_897_600 .. 4_611_669_811_199 seconds inclusive
(year -144169-01-01T00:00:00 .. 148107-12-31T23:59:59). Source:
yql/essentials/public/udf/udf_data_type.h.
On Windows, SystemTime cannot represent dates before 1601-01-01.
Timestamp64(SystemTime)
Signed timestamp, microsecond granularity. Wire format: int64 microseconds from UNIX epoch.
YDB range: -4_611_669_897_600_000_000 .. 4_611_669_811_199_999_999 µs inclusive
(year -144169-01-01T00:00:00.000000 .. 148107-12-31T23:59:59.999999). Source:
yql/essentials/public/udf/udf_data_type.h.
On Windows, SystemTime cannot represent dates before 1601-01-01.
Interval64(SignedInterval)
Signed duration, microsecond granularity. Wire format: int64 microseconds.
YDB range: ±9_223_339_708_799_999_999 µs (≈ ±292 270 years), derived as
MAX_TIMESTAMP64 - MIN_TIMESTAMP64. Source:
yql/essentials/public/udf/udf_data_type.h.
Sub-microsecond precision of the inner Duration is truncated on the wire.
Bytes(Bytes)
Text(String)
Text data, encoded to valid utf8
Yson(Bytes)
Json(String)
JsonDocument(String)
Optional(Box<ValueOptional>)
List(Box<ValueList>)
Struct(ValueStruct)
Decimal(YdbDecimal)
Uuid(Uuid)
Implementations§
Source§impl Value
impl Value
Sourcepub fn list_from(example_value: Value, values: Vec<Value>) -> YdbResult<Self>
pub fn list_from(example_value: Value, values: Vec<Value>) -> YdbResult<Self>
list_from create Value from example of item and values example value must be same type as items in value it used for describe type in query.
It can’t use one of values because values can be empty. Example:
let v = Value::list_from(0.into(), vec![1.into(), 2.into(), 3.into()])?;
}Sourcepub fn struct_from_fields(fields: Vec<(String, Value)>) -> Value
pub fn struct_from_fields(fields: Vec<(String, Value)>) -> Value
Create struct value from fields in form name, value.
Example:
let v = Value::struct_from_fields(vec![
("id".to_string(), 1.into()),
("value".to_string(), "test-value".into()),
]);Sourcepub fn is_optional(&self) -> bool
pub fn is_optional(&self) -> bool
Return true if the Value is optional
Trait Implementations§
Source§impl From<SystemTime> for Value
impl From<SystemTime> for Value
Source§fn from(value: SystemTime) -> Self
fn from(value: SystemTime) -> Self
Source§impl From<YdbDecimal> for Value
impl From<YdbDecimal> for Value
Source§fn from(d: YdbDecimal) -> Self
fn from(d: YdbDecimal) -> Self
Source§impl<T: Into<Value> + Default> FromIterator<T> for Value
impl<T: Into<Value> + Default> FromIterator<T> for Value
Source§fn from_iter<T2: IntoIterator<Item = T>>(iter: T2) -> Self
fn from_iter<T2: IntoIterator<Item = T>>(iter: T2) -> Self
Source§impl TryFrom<Value> for SystemTime
impl TryFrom<Value> for SystemTime
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze 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
impl<T> Any for T
Source§fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§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