Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move Emptiable and MaybeEmpty to scylla_cql::value
Old locations are kept until 2.0 for backwards compatibility.
The change is done because we will implement serialization for
MaybeEmpty.
  • Loading branch information
Lorak-mmk committed Jan 7, 2026
commit 1c22ee708cfe2895a039e689ecb9abff778a0daa
30 changes: 9 additions & 21 deletions scylla-cql/src/deserialize/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ use crate::value::{
CqlTimeuuid, CqlValue, CqlVarint, deser_cql_value,
};

// Re-export for backwards compatibility. These types were moved to crate::value module.
// Note: deprecated doesn't work on re-exports, users won't get the warning.
// Added it anyway for documentation purposes.
// TODO(2.0): Remove those re-exports.
#[deprecated(since = "1.5.0", note = "Moved to `scylla_cql::value` module")]
pub use crate::value::Emptiable;
#[deprecated(since = "1.5.0", note = "Moved to `scylla_cql::value` module")]
pub use crate::value::MaybeEmpty;

/// A type that can be deserialized from a column value inside a row that was
/// returned from a query.
///
Expand Down Expand Up @@ -92,27 +101,6 @@ where
}
}

/// Values that may be empty or not.
///
/// In CQL, some types can have a special value of "empty", represented as
/// a serialized value of length 0. An example of this are integral types:
/// the "int" type can actually hold 2^32 + 1 possible values because of this
/// quirk. Note that this is distinct from being NULL.
///
/// Rust types that cannot represent an empty value (e.g. i32) should implement
/// this trait in order to be deserialized as [MaybeEmpty].
pub trait Emptiable {}

/// A value that may be empty or not.
///
/// `MaybeEmpty` was introduced to help support the quirk described in [Emptiable]
/// for Rust types which can't represent the empty, additional value.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
pub enum MaybeEmpty<T: Emptiable> {
Empty,
Value(T),
}

impl<'frame, 'metadata, T> DeserializeValue<'frame, 'metadata> for MaybeEmpty<T>
where
T: DeserializeValue<'frame, 'metadata> + Emptiable,
Expand Down
23 changes: 23 additions & 0 deletions scylla-cql/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ impl<V> MaybeUnset<V> {
}
}

/// Values that may be empty or not.
///
/// In CQL, some types can have a special value of "empty", represented as
/// a serialized value of length 0. An example of this are integral types:
/// the "int" type can actually hold 2^32 + 1 possible values because of this
/// quirk. Note that this is distinct from being NULL.
///
/// Rust types that cannot represent an empty value (e.g. i32) should implement
/// this trait in order to be deserialized as [`MaybeEmpty`].
pub trait Emptiable {}

/// A value that may be empty or not.
///
/// `MaybeEmpty` was introduced to help support the quirk described in [`Emptiable`]
/// for Rust types which can't represent the empty, additional value.
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
pub enum MaybeEmpty<T: Emptiable> {
/// Represents an empty value (0 bytes in the serialized form).
Empty,
/// Represents a non-empty value.
Value(T),
}

/// Represents timeuuid (uuid V1) value
///
/// This type has custom comparison logic which follows ScyllaDB/Cassandra semantics.
Expand Down
13 changes: 10 additions & 3 deletions scylla/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ pub mod value {
// Every `pub` item is re-exported here, apart from `deser_cql_value`.
pub use scylla_cql::value::{
Counter, CqlDate, CqlDecimal, CqlDecimalBorrowed, CqlDuration, CqlTime, CqlTimestamp,
CqlTimeuuid, CqlValue, CqlVarint, CqlVarintBorrowed, MaybeUnset, Row, Unset, ValueOverflow,
CqlTimeuuid, CqlValue, CqlVarint, CqlVarintBorrowed, Emptiable, MaybeEmpty, MaybeUnset,
Row, Unset, ValueOverflow,
};
}

Expand Down Expand Up @@ -226,12 +227,18 @@ pub mod deserialize {
pub mod value {
pub use scylla_cql::deserialize::value::{
BuiltinDeserializationError, BuiltinDeserializationErrorKind, BuiltinTypeCheckError,
BuiltinTypeCheckErrorKind, DeserializeValue, Emptiable, ListlikeIterator,
MapDeserializationErrorKind, MapIterator, MapTypeCheckErrorKind, MaybeEmpty,
BuiltinTypeCheckErrorKind, DeserializeValue, ListlikeIterator,
MapDeserializationErrorKind, MapIterator, MapTypeCheckErrorKind,
SetOrListDeserializationErrorKind, SetOrListTypeCheckErrorKind,
TupleDeserializationErrorKind, TupleTypeCheckErrorKind, UdtIterator,
UdtTypeCheckErrorKind,
};

// Note: deprecated doesn't work on re-exports, users won't get the warning.
// Added it anyway for documentation purposes.
// TODO(2.0): Remove those re-exports.
#[deprecated(since = "1.5.0", note = "Moved to `scylla::value` module")]
pub use scylla_cql::deserialize::value::{Emptiable, MaybeEmpty};
}

// Shorthands for better readability.
Expand Down