Skip to content

Commit

Permalink
codewide: deprecate legacy serialization API's items
Browse files Browse the repository at this point in the history
Items constituting the legacy serialization API hadn't been marked with
the #[deprecated] attribute. As we're going to remove them soon, let's
warn users about that explicitly.
  • Loading branch information
wprzytula committed Dec 9, 2024
1 parent 8f5eb2f commit c136255
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 2 deletions.
1 change: 1 addition & 0 deletions scylla-cql/src/frame/response/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,7 @@ mod tests {
);
}

#[allow(deprecated)]
#[test]
fn test_serialize_empty() {
use crate::frame::value::Value;
Expand Down
12 changes: 12 additions & 0 deletions scylla-cql/src/frame/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ use super::types::RawValue;

#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[error("Value too big to be sent in a request - max 2GiB allowed")]
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
pub struct ValueTooBig;

#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[error("Value is too large to fit in the CQL type")]
pub struct ValueOverflow;

#[allow(deprecated)]
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum SerializeValuesError {
#[error("Too many values to add, max 65,535 values can be sent in a request")]
Expand Down Expand Up @@ -664,7 +669,13 @@ pub struct CqlDuration {
pub nanoseconds: i64,
}

#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
mod legacy {
#![allow(deprecated)]

use super::*;

/// Every value being sent in a query must implement this trait
Expand Down Expand Up @@ -1872,6 +1883,7 @@ mod legacy {
}
}
}
#[allow(deprecated)]
pub use legacy::{
LegacyBatchValues, LegacyBatchValuesFirstSerialized, LegacyBatchValuesFromIter,
LegacyBatchValuesIterator, LegacyBatchValuesIteratorFromIterator, LegacySerializedValues,
Expand Down
3 changes: 3 additions & 0 deletions scylla-cql/src/frame/value_tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// TODO: remove this once deprecated items are deleted.
#![allow(deprecated)]

use crate::frame::value::{CqlTimeuuid, CqlVarint};
use crate::frame::{response::result::CqlValue, types::RawValue, value::LegacyBatchValuesIterator};
use crate::types::serialize::batch::{BatchValues, BatchValuesIterator, LegacyBatchValuesAdapter};
Expand Down
3 changes: 3 additions & 0 deletions scylla-cql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ pub mod macros {
#[allow(deprecated)]
pub use crate::impl_from_cql_value_from_method;

#[allow(deprecated)]
pub use crate::impl_serialize_row_via_value_list;
#[allow(deprecated)]
pub use crate::impl_serialize_value_via_value;
}

Expand All @@ -35,6 +37,7 @@ pub mod _macro_internal {
FromCqlVal, FromCqlValError, FromRow, FromRowError,
};
pub use crate::frame::response::result::{ColumnSpec, ColumnType, CqlValue, Row};
#[allow(deprecated)]
pub use crate::frame::value::{
LegacySerializedValues, SerializedResult, Value, ValueList, ValueTooBig,
};
Expand Down
11 changes: 11 additions & 0 deletions scylla-cql/src/types/serialize/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Note: When editing above doc-comment edit the corresponding comment on
// re-export module in scylla crate too.

#[allow(deprecated)]
use crate::frame::value::{LegacyBatchValues, LegacyBatchValuesIterator};

use super::row::{RowSerializationContext, SerializeRow};
Expand Down Expand Up @@ -332,8 +333,13 @@ impl<T: BatchValues + ?Sized> BatchValues for &T {
/// Note that the [`LegacyBatchValues`] trait is deprecated and will be
/// removed in the future, and you should prefer using [`BatchValues`] as it is
/// more type-safe.
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
pub struct LegacyBatchValuesAdapter<T>(pub T);

#[allow(deprecated)]
impl<T> BatchValues for LegacyBatchValuesAdapter<T>
where
T: LegacyBatchValues,
Expand All @@ -351,8 +357,13 @@ where

/// A newtype wrapper which adjusts an existing types that implement
/// [`LegacyBatchValuesIterator`] to the current [`BatchValuesIterator`] API.
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
pub struct LegacyBatchValuesIteratorAdapter<T>(pub T);

#[allow(deprecated)]
impl<'r, T> BatchValuesIterator<'r> for LegacyBatchValuesIteratorAdapter<T>
where
T: LegacyBatchValuesIterator<'r>,
Expand Down
30 changes: 28 additions & 2 deletions scylla-cql/src/types/serialize/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::frame::request::RequestDeserializationError;
use crate::frame::response::result::ColumnType;
use crate::frame::response::result::PreparedMetadata;
use crate::frame::types;
use crate::frame::value::SerializeValuesError;
use crate::frame::value::{LegacySerializedValues, ValueList};
#[allow(deprecated)]
use crate::frame::value::{LegacySerializedValues, SerializeValuesError, ValueList};
use crate::frame::{response::result::ColumnSpec, types::RawValue};

use super::value::SerializeValue;
Expand Down Expand Up @@ -282,10 +282,12 @@ impl<T: SerializeRow + ?Sized> SerializeRow for &T {
}
}

#[allow(deprecated)]
impl SerializeRow for LegacySerializedValues {
fallback_impl_contents!();
}

#[allow(deprecated)]
impl SerializeRow for Cow<'_, LegacySerializedValues> {
fallback_impl_contents!();
}
Expand Down Expand Up @@ -409,6 +411,10 @@ impl_tuples!(
/// }
/// impl_serialize_row_via_value_list!(WithGenerics<T, U: Clone>);
/// ```
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
#[macro_export]
macro_rules! impl_serialize_row_via_value_list {
($t:ident$(<$($targ:tt $(: $tbound:tt)?),*>)?) => {
Expand Down Expand Up @@ -440,8 +446,13 @@ macro_rules! impl_serialize_row_via_value_list {
///
/// See the [`impl_serialize_row_via_value_list`] macro on information about
/// the properties of the [`SerializeRow`] implementation.
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
pub struct ValueListAdapter<T>(pub T);

#[allow(deprecated)]
impl<T> SerializeRow for ValueListAdapter<T>
where
T: ValueList,
Expand Down Expand Up @@ -482,6 +493,11 @@ where
///
/// See [`impl_serialize_row_via_value_list`] which generates a boilerplate
/// [`SerializeRow`] implementation that uses this function.
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
#[allow(deprecated)]
pub fn serialize_legacy_row<T: ValueList>(
r: &T,
ctx: &RowSerializationContext<'_>,
Expand Down Expand Up @@ -686,6 +702,11 @@ impl Display for BuiltinSerializationErrorKind {
/// Describes a failure to translate the output of the [`ValueList`] legacy trait
/// into an output of the [`SerializeRow`] trait.
#[derive(Error, Debug)]
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
#[allow(deprecated)]
pub enum ValueListToSerializeRowAdapterError {
/// The values generated by the [`ValueList`] trait were provided in
/// name-value pairs, and there is a column in the statement for which
Expand Down Expand Up @@ -921,7 +942,9 @@ pub(crate) mod tests {

use crate::frame::response::result::{ColumnSpec, ColumnType, TableSpec};
use crate::frame::types::RawValue;
#[allow(deprecated)]
use crate::frame::value::{LegacySerializedValues, MaybeUnset, SerializedResult, ValueList};
#[allow(deprecated)]
use crate::types::serialize::row::ValueListAdapter;
use crate::types::serialize::{RowWriter, SerializationError};

Expand All @@ -938,6 +961,7 @@ pub(crate) mod tests {
ColumnSpec::borrowed(name, typ, TableSpec::borrowed("ks", "tbl"))
}

#[allow(deprecated)]
#[test]
fn test_legacy_fallback() {
let row = (
Expand Down Expand Up @@ -967,6 +991,7 @@ pub(crate) mod tests {
assert_eq!(&legacy_data[2..], new_data);
}

#[allow(deprecated)]
#[test]
fn test_legacy_fallback_with_names() {
let sorted_row = (
Expand Down Expand Up @@ -1056,6 +1081,7 @@ pub(crate) mod tests {
ColumnSpec::borrowed(name, typ, TableSpec::borrowed("ks", "tbl"))
}

#[allow(deprecated)]
#[test]
fn test_legacy_wrapper() {
struct Foo;
Expand Down
24 changes: 24 additions & 0 deletions scylla-cql/src/types/serialize/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use uuid::Uuid;

use crate::frame::response::result::{ColumnType, CqlValue};
use crate::frame::types::vint_encode;
#[allow(deprecated)]
use crate::frame::value::{
Counter, CqlDate, CqlDecimal, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint,
MaybeUnset, Unset, Value,
Expand Down Expand Up @@ -926,6 +927,10 @@ fn serialize_mapping<'t, 'b, K: SerializeValue + 't, V: SerializeValue + 't>(
/// }
/// impl_serialize_value_via_value!(WithGenerics<T, U: Clone>);
/// ```
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
#[macro_export]
macro_rules! impl_serialize_value_via_value {
($t:ident$(<$($targ:tt $(: $tbound:tt)?),*>)?) => {
Expand All @@ -952,8 +957,13 @@ macro_rules! impl_serialize_value_via_value {
///
/// See the [`impl_serialize_value_via_value`] macro on information about
/// the properties of the [`SerializeValue`] implementation.
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
pub struct ValueAdapter<T>(pub T);

#[allow(deprecated)]
impl<T> SerializeValue for ValueAdapter<T>
where
T: Value,
Expand Down Expand Up @@ -981,6 +991,11 @@ where
///
/// See [`impl_serialize_value_via_value`] which generates a boilerplate
/// [`SerializeValue`] implementation that uses this function.
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
#[allow(deprecated)]
pub fn serialize_legacy_value<'b, T: Value>(
v: &T,
writer: CellWriter<'b>,
Expand Down Expand Up @@ -1465,6 +1480,11 @@ impl Display for UdtSerializationErrorKind {

/// Describes a failure to translate the output of the [`Value`] legacy trait
/// into an output of the [`SerializeValue`] trait.
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
#[allow(deprecated)]
#[derive(Error, Debug)]
pub enum ValueToSerializeValueAdapterError {
/// The value is too bit to be serialized as it exceeds the maximum 2GB size limit.
Expand Down Expand Up @@ -1598,7 +1618,9 @@ pub(crate) mod tests {
use std::collections::BTreeMap;

use crate::frame::response::result::{ColumnType, CqlValue};
#[allow(deprecated)]
use crate::frame::value::{Counter, MaybeUnset, Unset, Value, ValueTooBig};
#[allow(deprecated)]
use crate::types::serialize::value::{
BuiltinSerializationError, BuiltinSerializationErrorKind, BuiltinTypeCheckError,
BuiltinTypeCheckErrorKind, MapSerializationErrorKind, MapTypeCheckErrorKind,
Expand All @@ -1612,6 +1634,7 @@ pub(crate) mod tests {

use super::{SerializeValue, UdtSerializationErrorKind, UdtTypeCheckErrorKind};

#[allow(deprecated)]
fn check_compat<V: Value + SerializeValue>(v: V) {
let mut legacy_data = Vec::new();
<V as Value>::serialize(&v, &mut legacy_data).unwrap();
Expand Down Expand Up @@ -1662,6 +1685,7 @@ pub(crate) mod tests {
do_serialize_result(t, typ).unwrap_err()
}

#[allow(deprecated)]
#[test]
fn test_legacy_wrapper() {
struct Foo;
Expand Down
3 changes: 3 additions & 0 deletions scylla/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub mod serialize {
};

// Legacy migration types - to be removed when removing legacy framework
#[allow(deprecated)]
pub use scylla_cql::types::serialize::batch::{
LegacyBatchValuesAdapter, LegacyBatchValuesIteratorAdapter,
};
Expand All @@ -161,6 +162,7 @@ pub mod serialize {
};

// Legacy migration types - to be removed when removing legacy framework
#[allow(deprecated)]
pub use scylla_cql::types::serialize::row::{
// Legacy migration types - to be removed when removing legacy framework
serialize_legacy_row,
Expand Down Expand Up @@ -188,6 +190,7 @@ pub mod serialize {
};

// Legacy migration types - to be removed when removing legacy framework
#[allow(deprecated)]
pub use scylla_cql::types::serialize::value::{
serialize_legacy_value, ValueAdapter, ValueToSerializeValueAdapterError,
};
Expand Down
11 changes: 11 additions & 0 deletions scylla/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pub use scylla_cql::macros::FromUserType;
///
/// ---
///
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
#[allow(deprecated)]
pub use scylla_cql::macros::IntoUserType;

/// Derive macro for the [`SerializeValue`](crate::serialize::value::SerializeValue) trait
Expand Down Expand Up @@ -486,6 +491,10 @@ pub use scylla_macros::DeserializeRow;
///
/// ---
///
#[deprecated(
since = "0.15.1",
note = "Legacy serialization API is not type-safe and is going to be removed soon"
)]
pub use scylla_cql::macros::ValueList;

#[deprecated(
Expand All @@ -495,7 +504,9 @@ pub use scylla_cql::macros::ValueList;
#[allow(deprecated)]
pub use scylla_cql::macros::impl_from_cql_value_from_method;

#[allow(deprecated)]
pub use scylla_cql::macros::impl_serialize_row_via_value_list;
#[allow(deprecated)]
pub use scylla_cql::macros::impl_serialize_value_via_value;

// Reexports for derive(IntoUserType)
Expand Down

0 comments on commit c136255

Please sign in to comment.