#[non_exhaustive]pub enum Value {
Show 26 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),
Interval(SignedInterval),
Bytes(Bytes),
Text(String),
Yson(Bytes),
Json(String),
JsonDocument(String),
Optional(Box<ValueOptional>),
List(Box<ValueList>),
Struct(ValueStruct),
Decimal(Decimal),
}
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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future 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)
Interval(SignedInterval)
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(Decimal)
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
Converts to this type from the input type.
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
Creates a value from an iterator. Read more
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 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
TODO: once 1.33.0 is the minimum supported compiler version, remove
Any::type_id_compat and use StdAny::type_id instead.
https://github.com/rust-lang/rust/issues/27745
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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>
Wrap the input message
T
in a tonic::Request