Skip to main content
The ScyllaDB Rust Driver provides comprehensive support for serializing and deserializing CQL data types. This page provides an overview of how CQL types map to Rust types.

Type System

The driver’s type system consists of three main components:
  1. Native types - Basic scalar types like integers, strings, and UUIDs
  2. Collection types - Lists, sets, maps, and vectors
  3. Composite types - User-defined types (UDTs) and tuples

Type Mapping Table

The following table shows the mapping between CQL types and Rust types:
CQL TypeRust TypeNotes
asciiString, &strASCII-only strings
biginti6464-bit signed integer
blobVec<u8>, &[u8], BytesBinary data
booleanboolBoolean value
counterCounterCounter column type
dateCqlDate, chrono::NaiveDate, time::DateDays since epoch
decimalCqlDecimal, bigdecimal::BigDecimalVariable-precision decimal
doublef6464-bit floating point
durationCqlDurationDuration with nanosecond precision
floatf3232-bit floating point
inetIpAddrIPv4 or IPv6 address
inti3232-bit signed integer
smallinti1616-bit signed integer
textString, &strUTF-8 string
timeCqlTime, chrono::NaiveTime, time::TimeNanoseconds since midnight
timestampCqlTimestamp, chrono::DateTime<Utc>, time::OffsetDateTimeMilliseconds since epoch
timeuuidCqlTimeuuidUUID v1 (time-based)
tinyinti88-bit signed integer
uuidUuidUUID (any version)
varintCqlVarint, num_bigint::BigIntArbitrary-precision integer
list<T>Vec<T>Ordered collection
set<T>Vec<T>, HashSet<T>, BTreeSet<T>Unordered unique collection
map<K, V>HashMap<K, V>, BTreeMap<K, V>Key-value mapping
tuple<T1, T2, ...>(T1, T2, ...)Fixed-size heterogeneous collection
vector<T, N>Vec<T>Fixed-length vector
User-defined typeCustom struct with derive macrosStructured data

Serialization and Deserialization

The driver provides two main traits for type conversion:

SerializeValue

The SerializeValue trait is used to serialize Rust types into CQL values for sending to the database:
use scylla::serialize::value::SerializeValue;

let value: i32 = 42;
// value implements SerializeValue and can be used in queries

DeserializeValue

The DeserializeValue trait is used to deserialize CQL values received from the database into Rust types:
use scylla::deserialize::value::DeserializeValue;

let row = session.query_unpaged("SELECT id FROM table", &[]).await?;
if let Some(first_row) = row.rows()?.first() {
    let id: i32 = first_row.columns[0].as_ref()
        .and_then(|v| v.as_int())
        .unwrap();
}

Nullability

CQL supports null values for most types. In Rust, use Option<T> to represent nullable values:
let nullable_value: Option<i32> = None;
session.query_unpaged(
    "INSERT INTO table (id, value) VALUES (?, ?)",
    (1, nullable_value),
).await?;

Empty Values

Some CQL types support a special “empty” value (distinct from null). Use the MaybeEmpty<T> wrapper:
use scylla::value::MaybeEmpty;

let empty: MaybeEmpty<i32> = MaybeEmpty::Empty;
let value: MaybeEmpty<i32> = MaybeEmpty::Value(42);

Unset Values

To leave a value unset in an UPDATE or INSERT statement (which preserves the existing value), use MaybeUnset<T> or Unset:
use scylla::value::{MaybeUnset, Unset};

// Leave the value unset
let unset_value = MaybeUnset::<i32>::Unset;

// Or use Unset directly
session.query_unpaged(
    "INSERT INTO table (id, value) VALUES (?, ?)",
    (1, Unset),
).await?;

Feature Flags

Some type mappings require optional feature flags:
  • chrono-04 - Support for chrono 0.4 date/time types
  • time-03 - Support for time 0.3 date/time types
  • num-bigint-03 / num-bigint-04 - Support for arbitrary-precision integers
  • bigdecimal-04 - Support for arbitrary-precision decimals
  • secrecy-08 / secrecy-10 - Support for secret types

Type Safety

The driver performs type checking at runtime to ensure that Rust types match the expected CQL types. Type mismatches result in serialization or deserialization errors.

Next Steps

Build docs developers (and LLMs) love