Enum CqlValue

Source
#[non_exhaustive]
pub enum CqlValue {
Show 27 variants Ascii(String), Boolean(bool), Blob(Vec<u8>), Counter(Counter), Decimal(CqlDecimal), Date(CqlDate), Double(f64), Duration(CqlDuration), Empty, Float(f32), Int(i32), BigInt(i64), Text(String), Timestamp(CqlTimestamp), Inet(IpAddr), List(Vec<CqlValue>), Map(Vec<(CqlValue, CqlValue)>), Set(Vec<CqlValue>), UserDefinedType { keyspace: String, name: String, fields: Vec<(String, Option<CqlValue>)>, }, SmallInt(i16), TinyInt(i8), Time(CqlTime), Timeuuid(CqlTimeuuid), Tuple(Vec<Option<CqlValue>>), Uuid(Uuid), Varint(CqlVarint), Vector(Vec<CqlValue>),
}
Expand description

Represents all possible CQL values that can be returned by the database.

This type can represent a CQL value of any type. Therefore, it should be used in places where dynamic capabilities are needed, while, for efficiency purposes, avoided in places where the type of the value is known in the compile time.

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

Ascii(String)

ASCII-only string.

§

Boolean(bool)

Boolean value.

§

Blob(Vec<u8>)

Binary data of any length.

§

Counter(Counter)

Counter value, represented as a 64-bit integer.

§

Decimal(CqlDecimal)

Variable-precision decimal.

§

Date(CqlDate)

Days since -5877641-06-23 i.e. 2^31 days before unix epoch Can be converted to chrono::NaiveDate (-262145-1-1 to 262143-12-31) using TryInto.

§

Double(f64)

64-bit IEEE-754 floating point number.

§

Duration(CqlDuration)

A duration with nanosecond precision.

§

Empty

An empty value, which is distinct from null and is some DB legacy.

§

Float(f32)

32-bit IEEE-754 floating point number.

§

Int(i32)

32-bit signed integer.

§

BigInt(i64)

64-bit signed integer.

§

Text(String)

UTF-8 encoded string.

§

Timestamp(CqlTimestamp)

Milliseconds since unix epoch.

§

Inet(IpAddr)

IPv4 or IPv6 address.

§

List(Vec<CqlValue>)

A list of CQL values of the same types.

§

Map(Vec<(CqlValue, CqlValue)>)

A map of CQL values, whose all keys have the same type and all values have the same type.

§

Set(Vec<CqlValue>)

A set of CQL values of the same types.

§

UserDefinedType

A user-defined type (UDT) value. UDT is composed of fields, each with a name and an optional value of its own type.

Fields

§keyspace: String

Keyspace the type belongs to.

§name: String

Name of the user-defined type.

§fields: Vec<(String, Option<CqlValue>)>

Fields of the user-defined type - (name, value) pairs.

§

SmallInt(i16)

16-bit signed integer.

§

TinyInt(i8)

8-bit signed integer.

§

Time(CqlTime)

Nanoseconds since midnight.

§

Timeuuid(CqlTimeuuid)

Version 1 UUID, generally used as a “conflict-free” timestamp.

§

Tuple(Vec<Option<CqlValue>>)

A tuple of CQL values of independent types each, where each element can be None if the value is null. The length of the tuple is part of its CQL type.

§

Uuid(Uuid)

Universally unique identifier (UUID) of any version.

§

Varint(CqlVarint)

Arbitrary-precision integer.

§

Vector(Vec<CqlValue>)

A vector of CQL values of the same type. The length of the vector is part of its CQL type.

Implementations§

Source§

impl CqlValue

Source

pub fn as_ascii(&self) -> Option<&String>

Casts the value to ASCII string if it is of that type.

Source

pub fn as_cql_date(&self) -> Option<CqlDate>

Casts the value to CQL Date if it is of that type.

Source

pub fn as_cql_timestamp(&self) -> Option<CqlTimestamp>

Casts the value to CQL Timestamp if it is of that type.

Source

pub fn as_cql_time(&self) -> Option<CqlTime>

Casts the value to CQL Time if it is of that type.

Source

pub fn as_cql_duration(&self) -> Option<CqlDuration>

Casts the value to CQL Duration if it is of that type.

Source

pub fn as_counter(&self) -> Option<Counter>

Casts the value to CQL Counter if it is of that type.

Source

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

Casts the value to bool if it is of that type.

Source

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

Casts the value to double-precision float if it is of that type.

Source

pub fn as_uuid(&self) -> Option<Uuid>

Casts the value to UUID if it is of that type.

Source

pub fn as_float(&self) -> Option<f32>

Casts the value to single-precision float if it is of that type.

Source

pub fn as_int(&self) -> Option<i32>

Casts the value to 32-bit signed integer if it is of that type.

Source

pub fn as_bigint(&self) -> Option<i64>

Casts the value to 64-bit signed integer if it is of that type.

Source

pub fn as_tinyint(&self) -> Option<i8>

Casts the value to 8-bit signed integer if it is of that type.

Source

pub fn as_smallint(&self) -> Option<i16>

Casts the value to 16-bit signed integer if it is of that type.

Source

pub fn as_blob(&self) -> Option<&Vec<u8>>

Casts the value to a byte sequence if it is of blob type.

Source

pub fn as_text(&self) -> Option<&String>

Casts the value to UTF-8 encoded string if it is of text type.

Source

pub fn as_timeuuid(&self) -> Option<CqlTimeuuid>

Casts the value to CQL Timeuuid if it is of that type.

Source

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

Converts the value to string if it is of ascii or text type.

Source

pub fn into_blob(self) -> Option<Vec<u8>>

Converts the value to a byte sequence if it is of blob type.

Source

pub fn as_inet(&self) -> Option<IpAddr>

Casts the value to an IP address if it is of inet type.

Source

pub fn as_list(&self) -> Option<&Vec<CqlValue>>

Casts the value to a vec of CQL values if it is of list type.

Source

pub fn as_set(&self) -> Option<&Vec<CqlValue>>

Casts the value to a vec of CQL values if it is of set type.

Source

pub fn as_map(&self) -> Option<&Vec<(CqlValue, CqlValue)>>

Casts the value to a vec of pairs of CQL values if it is of map type, where each pair is a key-value pair.

Source

pub fn as_udt(&self) -> Option<&Vec<(String, Option<CqlValue>)>>

Casts the value to a user-defined type (UDT) if it is of that type. The UDT is represented as a vector of pairs, where each pair consists of a field name and an optional (=nullable) value.

Source

pub fn into_vec(self) -> Option<Vec<CqlValue>>

Converts the value to a vector of CQL values if it is of list or set type.

Source

pub fn into_pair_vec(self) -> Option<Vec<(CqlValue, CqlValue)>>

Converts the value to a vec of pairs of CQL values if it is of map type, where each pair is a key-value pair.

Source

pub fn into_udt_pair_vec(self) -> Option<Vec<(String, Option<CqlValue>)>>

Converts the value to a vec of pairs if it is a user-defined type (UDT). Each pair consists of a field name and an optional (=nullable) value.

Source

pub fn into_cql_varint(self) -> Option<CqlVarint>

Converts the value to CQL Varint if it is of that type.

Source

pub fn into_cql_decimal(self) -> Option<CqlDecimal>

Converts the value to CQL Decimal if it is of that type.

Trait Implementations§

Source§

impl Clone for CqlValue

Source§

fn clone(&self) -> CqlValue

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CqlValue

Source§

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

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

impl<'frame, 'metadata> DeserializeValue<'frame, 'metadata> for CqlValue

Source§

fn type_check(_typ: &ColumnType<'_>) -> Result<(), TypeCheckError>

Checks that the column type matches what this type expects.
Source§

fn deserialize( typ: &'metadata ColumnType<'metadata>, v: Option<FrameSlice<'frame>>, ) -> Result<Self, DeserializationError>

Deserialize a column value from given serialized representation. Read more
Source§

impl Display for CqlValue

Displays a CqlValue. The syntax should resemble the CQL literal syntax (but no guarantee is given that it’s always the same).

Source§

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

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

impl PartialEq for CqlValue

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl SerializeValue for CqlValue

Source§

fn serialize<'b>( &self, typ: &ColumnType<'_>, writer: CellWriter<'b>, ) -> Result<WrittenCellProof<'b>, SerializationError>

Serializes the value to given CQL type. Read more
Source§

impl StructuralPartialEq for CqlValue

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<T> ErasedDestructor for T
where T: 'static,