From 4c77b9bae3eb07f69b0adfa464b5cb6f19f561b4 Mon Sep 17 00:00:00 2001 From: muzarski Date: Tue, 14 May 2024 14:33:51 +0200 Subject: [PATCH 1/4] treewide: SerializeCql -> SerializeValue Replaced all occurrences of SerializeCql with SerializeValue. --- docs/source/data-types/udt.md | 16 +- .../migration-guides/0.11-serialization.md | 22 +- examples/user-defined-type.rs | 4 +- examples/value_list.rs | 2 +- scylla-cql/src/frame/value_tests.rs | 14 +- scylla-cql/src/lib.rs | 4 +- scylla-cql/src/types/serialize/mod.rs | 4 +- scylla-cql/src/types/serialize/row.rs | 35 ++- scylla-cql/src/types/serialize/value.rs | 259 +++++++++--------- scylla-cql/src/types/serialize/writers.rs | 4 +- scylla-macros/src/lib.rs | 2 +- scylla-macros/src/serialize/cql.rs | 8 +- scylla-macros/src/serialize/row.rs | 4 +- scylla/src/macros.rs | 12 +- scylla/src/transport/cql_collections_test.rs | 4 +- scylla/src/transport/cql_types_test.rs | 18 +- scylla/src/transport/locator/tablets.rs | 9 +- scylla/src/transport/session_test.rs | 18 +- scylla/tests/integration/hygiene.rs | 2 +- 19 files changed, 224 insertions(+), 217 deletions(-) diff --git a/docs/source/data-types/udt.md b/docs/source/data-types/udt.md index c2ed650738..eadbfe1d48 100644 --- a/docs/source/data-types/udt.md +++ b/docs/source/data-types/udt.md @@ -9,24 +9,24 @@ CREATE TYPE ks.my_type (int_val int, text_val text) ``` To use this type in the driver, create a matching struct and derive: -- `SerializeCql`: in order to be able to use this struct in query parameters. \ +- `SerializeValue`: in order to be able to use this struct in query parameters. \ This macro requires fields of UDT and struct to have matching names, but the order of the fields is not required to be the same. \ - Note: you can use different name using `rename` attribute - see `SerializeCql` macro documentation. + Note: you can use different name using `rename` attribute - see `SerializeValue` macro documentation. - `FromUserType`: in order to be able to use this struct in query results. \ This macro requires fields of UDT and struct to be in the same *ORDER*. \ - This mismatch between `SerializeCql` and `FromUserType` requirements is a temporary situation - in the future `FromUserType` (or the macro that replaces it) will also require matching names. + This mismatch between `SerializeValue` and `FromUserType` requirements is a temporary situation - in the future `FromUserType` (or the macro that replaces it) will also require matching names. ```rust # extern crate scylla; # async fn check_only_compiles() { -use scylla::macros::{FromUserType, SerializeCql}; +use scylla::macros::{FromUserType, SerializeValue}; // Define a custom struct that matches the User Defined Type created earlier. // Fields must be in the same order as they are in the database and also // have the same names. // Wrapping a field in Option will gracefully handle null field values. -#[derive(Debug, FromUserType, SerializeCql)] +#[derive(Debug, FromUserType, SerializeValue)] struct MyType { int_val: i32, text_val: Option, @@ -41,7 +41,7 @@ struct MyType { > ***Important***\ > For serialization, by default fields in the Rust struct must be defined with the same names as they are in the database. > The driver will serialize the fields in the order defined by the UDT, matching Rust fields by name. -> You can change this behaviour using macro attributes, see `SerializeCql` macro documentation for more information. +> You can change this behaviour using macro attributes, see `SerializeValue` macro documentation for more information. Now it can be sent and received just like any other CQL value: ```rust @@ -50,10 +50,10 @@ Now it can be sent and received just like any other CQL value: # use std::error::Error; # async fn check_only_compiles(session: &Session) -> Result<(), Box> { use scylla::IntoTypedRows; -use scylla::macros::{FromUserType, SerializeCql}; +use scylla::macros::{FromUserType, SerializeValue}; use scylla::cql_to_rust::FromCqlVal; -#[derive(Debug, FromUserType, SerializeCql)] +#[derive(Debug, FromUserType, SerializeValue)] struct MyType { int_val: i32, text_val: Option, diff --git a/docs/source/migration-guides/0.11-serialization.md b/docs/source/migration-guides/0.11-serialization.md index 4df222592c..36a264004d 100644 --- a/docs/source/migration-guides/0.11-serialization.md +++ b/docs/source/migration-guides/0.11-serialization.md @@ -28,19 +28,19 @@ In version 0.11, a new set of traits is introduced and the old ones are deprecat Both the old and the new APIs are based on three core traits: -- `Value` - called `SerializeCql` in the new API. A type that can serialize itself to a single CQL value. For example, `i32` serializes itself into a representation that is compatible with the CQL `int` type. +- `Value` - called `SerializeValue` in the new API. A type that can serialize itself to a single CQL value. For example, `i32` serializes itself into a representation that is compatible with the CQL `int` type. - `ValueList` - called `SerializeRow` in the new API. A type that can serialize itself as a list of values for a CQL statement. For example, a `(i32, &str)` produces a list of two values which can be used in a query with two bind markers, e.g. `SELECT * FROM table WHERE pk = ? AND ck = ?`. Optionally, values in the produced list may be associated with names which is useful when using it with a query with named bind markers, e.g. `SELECT * FROM table WHERE pk = :pk AND ck = :ck`. - `LegacyBatchValues`, previously named `BatchValues` - in new API replaced with new trait called (again) `BatchValues`. Represents a source of data for a batch request. It is essentially equivalent to a list of `ValueList`, one for each statement in the batch. For example, `((1, 2), (3, 4, 5))` can be used for a batch with two statements, the first one having two bind markers and the second one having three. All methods which take one of the old traits were changed to take the new trait - notably, this includes `Session::query`, `(Caching)Session::execute`, `(Caching)Session::batch`. -The driver comes a set of `impl`s of those traits which allow to represent any CQL type (for example, see [Data Types](../data-types/data-types.md) page for a list of for which `Value` and `SerializeCql` is implemented). If the driver implements an old trait for some type, then it also provides implements the new trait for the same type. +The driver comes a set of `impl`s of those traits which allow to represent any CQL type (for example, see [Data Types](../data-types/data-types.md) page for a list of for which `Value` and `SerializeValue` is implemented). If the driver implements an old trait for some type, then it also provides implements the new trait for the same type. ## Migration scenarios -### Different default behavior in `SerializeRow`/`SerializeCql` macros +### Different default behavior in `SerializeRow`/`SerializeValue` macros -By default, the `SerializeRow` and `SerializeCql` **will match the fields in the Rust struct by name to bind marker names** (in case of `SerializeRow`) **or UDT field names** (in case of `SerializeCql`). This is different from the old `ValueList` and `IntoUserType` macros which did not look at the field names at all and would expect the user to order the fields correctly. While the new behavior is much more ergonomic, you might have reasons not to use it. +By default, the `SerializeRow` and `SerializeValue` **will match the fields in the Rust struct by name to bind marker names** (in case of `SerializeRow`) **or UDT field names** (in case of `SerializeValue`). This is different from the old `ValueList` and `IntoUserType` macros which did not look at the field names at all and would expect the user to order the fields correctly. While the new behavior is much more ergonomic, you might have reasons not to use it. > **NOTE:** The deserialization macro counterparts `FromRow` and `FromUserType` have the same limitation as the old serialization macros - they require struct fields to be properly ordered. While a similar rework is planned for the deserialization traits in a future release, for the time being it might not be worth keeping the column names in sync with the database. @@ -48,11 +48,11 @@ In order to bring the old behavior to the new macros (the only difference being ```rust # extern crate scylla; -use scylla::SerializeCql; +use scylla::SerializeValue; // The exact same attributes apply to the `SerializeRow` macro and their // effect is completely analogous. -#[derive(SerializeCql)] +#[derive(SerializeValue)] #[scylla(flavor = "enforce_order", skip_name_checks)] struct Person { name: String, @@ -61,7 +61,7 @@ struct Person { } ``` -Refer to the API reference page for the `SerializeRow` and `SerializeCql` macros in the `scylla` crate to learn more about the supported attributes and their meaning. +Refer to the API reference page for the `SerializeRow` and `SerializeValue` macros in the `scylla` crate to learn more about the supported attributes and their meaning. ### Preparing is mandatory with a non-empty list of values @@ -80,13 +80,13 @@ In both cases, if the additional roundtrips are unacceptable, you should prepare ### Migrating from old to new traits *gradually* -In some cases, migration will be as easy as changing occurrences of `IntoUserType` to `SerializeCql` and `ValueList` to `SerializeRow` and adding some atributes for procedural macros. However, if you have a large enough codebase or some custom, complicated implementations of the old traits then you might not want to migrate everything at once. To support gradual migration, the old traits were not removed but rather deprecated, and we introduced some additional utilities. +In some cases, migration will be as easy as changing occurrences of `IntoUserType` to `SerializeValue` and `ValueList` to `SerializeRow` and adding some atributes for procedural macros. However, if you have a large enough codebase or some custom, complicated implementations of the old traits then you might not want to migrate everything at once. To support gradual migration, the old traits were not removed but rather deprecated, and we introduced some additional utilities. #### Converting an object implementing an old trait to a new trait We provide a number of newtype wrappers: -- `ValueAdapter` - implements `SerializeCql` if the type wrapped over implements `Value`, +- `ValueAdapter` - implements `SerializeValue` if the type wrapped over implements `Value`, - `ValueListAdapter` - implements `SerializeRow` if the type wrapped over implements `ValueList`, - `LegacyBatchValuesAdapter` - implements `BatchValues` if the type wrapped over implements `LegacyBatchValues`. @@ -98,9 +98,9 @@ Conversion in the other direction is not possible. #### Custom implementations of old traits -It is possible to directly generate an `impl` of `SerializeRow` and `SerializeCql` on a type which implements, respectively, `ValueList` or `Value`, without using the wrappers from the previous section. The following macros are provided: +It is possible to directly generate an `impl` of `SerializeRow` and `SerializeValue` on a type which implements, respectively, `ValueList` or `Value`, without using the wrappers from the previous section. The following macros are provided: -- `impl_serialize_cql_via_value` - implements `SerializeCql` if the type wrapped over implements `Value`, +- `impl_serialize_cql_via_value` - implements `SerializeValue` if the type wrapped over implements `Value`, - `impl_serialize_row_via_value_list` - implements `SerializeRow` if the type wrapped over implements `ValueList`, The implementations are practically as those generated by the wrappers described in the previous section. diff --git a/examples/user-defined-type.rs b/examples/user-defined-type.rs index 40ec38685e..4db980b791 100644 --- a/examples/user-defined-type.rs +++ b/examples/user-defined-type.rs @@ -1,6 +1,6 @@ use anyhow::Result; use scylla::macros::FromUserType; -use scylla::{SerializeCql, Session, SessionBuilder}; +use scylla::{SerializeValue, Session, SessionBuilder}; use std::env; #[tokio::main] @@ -29,7 +29,7 @@ async fn main() -> Result<()> { // Define custom struct that matches User Defined Type created earlier // wrapping field in Option will gracefully handle null field values - #[derive(Debug, FromUserType, SerializeCql)] + #[derive(Debug, FromUserType, SerializeValue)] struct MyType { int_val: i32, text_val: Option, diff --git a/examples/value_list.rs b/examples/value_list.rs index fe03b154bf..8cb4157e87 100644 --- a/examples/value_list.rs +++ b/examples/value_list.rs @@ -40,7 +40,7 @@ async fn main() { // You can also use type generics: #[derive(scylla::SerializeRow)] - struct MyTypeWithGenerics { + struct MyTypeWithGenerics { k: i32, my: Option, } diff --git a/scylla-cql/src/frame/value_tests.rs b/scylla-cql/src/frame/value_tests.rs index f15c5793fd..7af026d124 100644 --- a/scylla-cql/src/frame/value_tests.rs +++ b/scylla-cql/src/frame/value_tests.rs @@ -2,7 +2,7 @@ use crate::frame::value::{CqlTimeuuid, CqlVarint}; use crate::frame::{response::result::CqlValue, types::RawValue, value::LegacyBatchValuesIterator}; use crate::types::serialize::batch::{BatchValues, BatchValuesIterator, LegacyBatchValuesAdapter}; use crate::types::serialize::row::{RowSerializationContext, SerializeRow}; -use crate::types::serialize::value::SerializeCql; +use crate::types::serialize::value::SerializeValue; use crate::types::serialize::{CellWriter, RowWriter}; use super::response::result::{ColumnSpec, ColumnType, TableSpec}; @@ -23,24 +23,24 @@ use uuid::Uuid; fn serialized(val: T, typ: ColumnType) -> Vec where - T: Value + SerializeCql, + T: Value + SerializeValue, { let mut result: Vec = Vec::new(); Value::serialize(&val, &mut result).unwrap(); let mut new_result: Vec = Vec::new(); let writer = CellWriter::new(&mut new_result); - SerializeCql::serialize(&val, &typ, writer).unwrap(); + SerializeValue::serialize(&val, &typ, writer).unwrap(); assert_eq!(result, new_result); result } -fn serialized_only_new(val: T, typ: ColumnType) -> Vec { +fn serialized_only_new(val: T, typ: ColumnType) -> Vec { let mut result: Vec = Vec::new(); let writer = CellWriter::new(&mut result); - SerializeCql::serialize(&val, &typ, writer).unwrap(); + SerializeValue::serialize(&val, &typ, writer).unwrap(); result } @@ -169,7 +169,7 @@ fn varint_test_cases_from_spec() -> Vec<(i64, Vec)> { #[cfg(any(feature = "num-bigint-03", feature = "num-bigint-04"))] fn generic_num_bigint_serialization() where - B: From + Value + SerializeCql, + B: From + Value + SerializeValue, { let cases_from_the_spec: &[(i64, Vec)] = &varint_test_cases_from_spec(); @@ -824,7 +824,7 @@ fn cqlvalue_serialization() { ] ); - // Unlike the legacy Value trait, SerializeCql takes case of reordering + // Unlike the legacy Value trait, SerializeValue takes case of reordering // the fields let udt = CqlValue::UserDefinedType { keyspace: "ks".to_string(), diff --git a/scylla-cql/src/lib.rs b/scylla-cql/src/lib.rs index 95794184db..f8b3e07995 100644 --- a/scylla-cql/src/lib.rs +++ b/scylla-cql/src/lib.rs @@ -5,8 +5,8 @@ pub mod macros { pub use scylla_macros::FromRow; pub use scylla_macros::FromUserType; pub use scylla_macros::IntoUserType; - pub use scylla_macros::SerializeCql; pub use scylla_macros::SerializeRow; + pub use scylla_macros::SerializeValue; pub use scylla_macros::ValueList; // Reexports for derive(IntoUserType) @@ -44,7 +44,7 @@ pub mod _macro_internal { BuiltinSerializationError as BuiltinTypeSerializationError, BuiltinSerializationErrorKind as BuiltinTypeSerializationErrorKind, BuiltinTypeCheckError as BuiltinTypeTypeCheckError, - BuiltinTypeCheckErrorKind as BuiltinTypeTypeCheckErrorKind, SerializeCql, + BuiltinTypeCheckErrorKind as BuiltinTypeTypeCheckErrorKind, SerializeValue, UdtSerializationErrorKind, UdtTypeCheckErrorKind, }; pub use crate::types::serialize::writers::WrittenCellProof; diff --git a/scylla-cql/src/types/serialize/mod.rs b/scylla-cql/src/types/serialize/mod.rs index 7c6c62c7a7..b086dd5dcc 100644 --- a/scylla-cql/src/types/serialize/mod.rs +++ b/scylla-cql/src/types/serialize/mod.rs @@ -24,9 +24,9 @@ pub use writers::{CellValueBuilder, CellWriter, RowWriter}; /// one of types with an impl built into the driver fails. It is also returned /// from impls generated by the `SerializeRow` macro. /// - [`value::BuiltinSerializationError`] is analogous to the above but is -/// returned from [`SerializeCql::serialize`](value::SerializeCql::serialize) +/// returned from [`SerializeValue::serialize`](value::SerializeValue::serialize) /// instead both in the case of builtin impls and impls generated by the -/// `SerializeCql` macro. It won't be returned by the `Session` directly, +/// `SerializeValue` macro. It won't be returned by the `Session` directly, /// but it might be nested in the [`row::BuiltinSerializationError`]. /// - [`row::ValueListToSerializeRowAdapterError`] is returned in case when /// a list of named values encoded with the legacy `ValueList` trait is passed diff --git a/scylla-cql/src/types/serialize/row.rs b/scylla-cql/src/types/serialize/row.rs index f980064388..236451d59b 100644 --- a/scylla-cql/src/types/serialize/row.rs +++ b/scylla-cql/src/types/serialize/row.rs @@ -17,7 +17,7 @@ use crate::frame::value::SerializeValuesError; use crate::frame::value::{LegacySerializedValues, ValueList}; use crate::frame::{response::result::ColumnSpec, types::RawValue}; -use super::value::SerializeCql; +use super::value::SerializeValue; use super::{CellWriter, RowWriter, SerializationError}; /// Contains information needed to serialize a row. @@ -148,16 +148,15 @@ macro_rules! impl_serialize_row_for_slice { )); } for (col, val) in ctx.columns().iter().zip(self.iter()) { - ::serialize(val, &col.typ, writer.make_cell_writer()).map_err( - |err| { + ::serialize(val, &col.typ, writer.make_cell_writer()) + .map_err(|err| { mk_ser_err::( BuiltinSerializationErrorKind::ColumnSerializationFailed { name: col.name.clone(), err, }, ) - }, - )?; + })?; } Ok(()) } @@ -169,11 +168,11 @@ macro_rules! impl_serialize_row_for_slice { }; } -impl<'a, T: SerializeCql + 'a> SerializeRow for &'a [T] { +impl<'a, T: SerializeValue + 'a> SerializeRow for &'a [T] { impl_serialize_row_for_slice!(); } -impl SerializeRow for Vec { +impl SerializeRow for Vec { impl_serialize_row_for_slice!(); } @@ -199,7 +198,7 @@ macro_rules! impl_serialize_row_for_map { )) } Some(v) => { - ::serialize(v, &col.typ, writer.make_cell_writer()) + ::serialize(v, &col.typ, writer.make_cell_writer()) .map_err(|err| { mk_ser_err::( BuiltinSerializationErrorKind::ColumnSerializationFailed { @@ -233,19 +232,19 @@ macro_rules! impl_serialize_row_for_map { }; } -impl SerializeRow for BTreeMap { +impl SerializeRow for BTreeMap { impl_serialize_row_for_map!(); } -impl SerializeRow for BTreeMap<&str, T> { +impl SerializeRow for BTreeMap<&str, T> { impl_serialize_row_for_map!(); } -impl SerializeRow for HashMap { +impl SerializeRow for HashMap { impl_serialize_row_for_map!(); } -impl SerializeRow for HashMap<&str, T, S> { +impl SerializeRow for HashMap<&str, T, S> { impl_serialize_row_for_map!(); } @@ -279,7 +278,7 @@ macro_rules! impl_tuple { $($tidents:ident),*; $length:expr ) => { - impl<$($typs: SerializeCql),*> SerializeRow for ($($typs,)*) { + impl<$($typs: SerializeValue),*> SerializeRow for ($($typs,)*) { fn serialize( &self, ctx: &RowSerializationContext<'_>, @@ -296,7 +295,7 @@ macro_rules! impl_tuple { }; let ($($fidents,)*) = self; $( - <$typs as SerializeCql>::serialize($fidents, &$tidents.typ, writer.make_cell_writer()).map_err(|err| { + <$typs as SerializeValue>::serialize($fidents, &$tidents.typ, writer.make_cell_writer()).map_err(|err| { mk_ser_err::(BuiltinSerializationErrorKind::ColumnSerializationFailed { name: $tidents.name.clone(), err, @@ -784,7 +783,7 @@ impl SerializedValues { } /// Serializes value and appends it to the list - pub fn add_value( + pub fn add_value( &mut self, val: &T, typ: &ColumnType, @@ -861,7 +860,7 @@ mod tests { use super::{ BuiltinSerializationError, BuiltinSerializationErrorKind, BuiltinTypeCheckError, - BuiltinTypeCheckErrorKind, RowSerializationContext, SerializeCql, SerializeRow, + BuiltinTypeCheckErrorKind, RowSerializationContext, SerializeRow, SerializeValue, }; use super::SerializedValues; @@ -1254,7 +1253,7 @@ mod tests { #[derive(SerializeRow)] #[scylla(crate = crate)] - struct TestRowWithGenerics<'a, T: SerializeCql> { + struct TestRowWithGenerics<'a, T: SerializeValue> { a: &'a str, b: T, } @@ -1262,7 +1261,7 @@ mod tests { #[test] fn test_row_serialization_with_generics() { // A minimal smoke test just to test that it works. - fn check_with_type(typ: ColumnType, t: T) { + fn check_with_type(typ: ColumnType, t: T) { let spec = [col("a", ColumnType::Text), col("b", typ)]; let reference = do_serialize(("Ala ma kota", t), &spec); let row = do_serialize( diff --git a/scylla-cql/src/types/serialize/value.rs b/scylla-cql/src/types/serialize/value.rs index b5e6181d01..83b1e86068 100644 --- a/scylla-cql/src/types/serialize/value.rs +++ b/scylla-cql/src/types/serialize/value.rs @@ -1,4 +1,4 @@ -//! Contains the [`SerializeCql`] trait and its implementations. +//! Contains the [`SerializeValue`] trait and its implementations. use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; use std::fmt::Display; @@ -34,7 +34,7 @@ use super::{CellWriter, SerializationError}; /// protocol and usually does not have to be implemented directly. See the /// chapter on "Query Values" in the driver docs for information about how /// this trait is supposed to be used. -pub trait SerializeCql { +pub trait SerializeValue { /// Serializes the value to given CQL type. /// /// The value should produce a `[value]`, according to the [CQL protocol @@ -90,31 +90,31 @@ macro_rules! impl_serialize_via_writer { }; } -impl SerializeCql for i8 { +impl SerializeValue for i8 { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, TinyInt); writer.set_value(me.to_be_bytes().as_slice()).unwrap() }); } -impl SerializeCql for i16 { +impl SerializeValue for i16 { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, SmallInt); writer.set_value(me.to_be_bytes().as_slice()).unwrap() }); } -impl SerializeCql for i32 { +impl SerializeValue for i32 { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Int); writer.set_value(me.to_be_bytes().as_slice()).unwrap() }); } -impl SerializeCql for i64 { +impl SerializeValue for i64 { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, BigInt); writer.set_value(me.to_be_bytes().as_slice()).unwrap() }); } -impl SerializeCql for CqlDecimal { +impl SerializeValue for CqlDecimal { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Decimal); let mut builder = writer.into_value_builder(); @@ -127,7 +127,7 @@ impl SerializeCql for CqlDecimal { }); } #[cfg(feature = "bigdecimal-04")] -impl SerializeCql for bigdecimal_04::BigDecimal { +impl SerializeValue for bigdecimal_04::BigDecimal { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Decimal); let mut builder = writer.into_value_builder(); @@ -142,71 +142,71 @@ impl SerializeCql for bigdecimal_04::BigDecimal { .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? }); } -impl SerializeCql for CqlDate { +impl SerializeValue for CqlDate { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Date); writer.set_value(me.0.to_be_bytes().as_slice()).unwrap() }); } -impl SerializeCql for CqlTimestamp { +impl SerializeValue for CqlTimestamp { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Timestamp); writer.set_value(me.0.to_be_bytes().as_slice()).unwrap() }); } -impl SerializeCql for CqlTime { +impl SerializeValue for CqlTime { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Time); writer.set_value(me.0.to_be_bytes().as_slice()).unwrap() }); } #[cfg(feature = "chrono")] -impl SerializeCql for NaiveDate { +impl SerializeValue for NaiveDate { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Date); - ::serialize(&(*me).into(), typ, writer)? + ::serialize(&(*me).into(), typ, writer)? }); } #[cfg(feature = "chrono")] -impl SerializeCql for DateTime { +impl SerializeValue for DateTime { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Timestamp); - ::serialize(&(*me).into(), typ, writer)? + ::serialize(&(*me).into(), typ, writer)? }); } #[cfg(feature = "chrono")] -impl SerializeCql for NaiveTime { +impl SerializeValue for NaiveTime { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Time); let cql_time = CqlTime::try_from(*me).map_err(|_: ValueOverflow| { mk_ser_err::(typ, BuiltinSerializationErrorKind::ValueOverflow) })?; - ::serialize(&cql_time, typ, writer)? + ::serialize(&cql_time, typ, writer)? }); } #[cfg(feature = "time")] -impl SerializeCql for time::Date { +impl SerializeValue for time::Date { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Date); - ::serialize(&(*me).into(), typ, writer)? + ::serialize(&(*me).into(), typ, writer)? }); } #[cfg(feature = "time")] -impl SerializeCql for time::OffsetDateTime { +impl SerializeValue for time::OffsetDateTime { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Timestamp); - ::serialize(&(*me).into(), typ, writer)? + ::serialize(&(*me).into(), typ, writer)? }); } #[cfg(feature = "time")] -impl SerializeCql for time::Time { +impl SerializeValue for time::Time { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Time); - ::serialize(&(*me).into(), typ, writer)? + ::serialize(&(*me).into(), typ, writer)? }); } #[cfg(feature = "secret")] -impl SerializeCql for Secret { +impl SerializeValue for Secret { fn serialize<'b>( &self, typ: &ColumnType, @@ -215,37 +215,37 @@ impl SerializeCql for Secret { V::serialize(self.expose_secret(), typ, writer) } } -impl SerializeCql for bool { +impl SerializeValue for bool { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Boolean); writer.set_value(&[*me as u8]).unwrap() }); } -impl SerializeCql for f32 { +impl SerializeValue for f32 { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Float); writer.set_value(me.to_be_bytes().as_slice()).unwrap() }); } -impl SerializeCql for f64 { +impl SerializeValue for f64 { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Double); writer.set_value(me.to_be_bytes().as_slice()).unwrap() }); } -impl SerializeCql for Uuid { +impl SerializeValue for Uuid { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Uuid); writer.set_value(me.as_bytes().as_ref()).unwrap() }); } -impl SerializeCql for CqlTimeuuid { +impl SerializeValue for CqlTimeuuid { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Timeuuid); writer.set_value(me.as_bytes().as_ref()).unwrap() }); } -impl SerializeCql for CqlVarint { +impl SerializeValue for CqlVarint { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Varint); writer @@ -254,7 +254,7 @@ impl SerializeCql for CqlVarint { }); } #[cfg(feature = "num-bigint-03")] -impl SerializeCql for num_bigint_03::BigInt { +impl SerializeValue for num_bigint_03::BigInt { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Varint); // TODO: The allocation here can be avoided and we can reimplement @@ -266,7 +266,7 @@ impl SerializeCql for num_bigint_03::BigInt { }); } #[cfg(feature = "num-bigint-04")] -impl SerializeCql for num_bigint_04::BigInt { +impl SerializeValue for num_bigint_04::BigInt { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Varint); // TODO: See above comment for num-bigint-03. @@ -275,7 +275,7 @@ impl SerializeCql for num_bigint_04::BigInt { .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? }); } -impl SerializeCql for &str { +impl SerializeValue for &str { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Ascii, Text); writer @@ -283,7 +283,7 @@ impl SerializeCql for &str { .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? }); } -impl SerializeCql for Vec { +impl SerializeValue for Vec { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Blob); writer @@ -291,7 +291,7 @@ impl SerializeCql for Vec { .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? }); } -impl SerializeCql for &[u8] { +impl SerializeValue for &[u8] { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Blob); writer @@ -299,7 +299,7 @@ impl SerializeCql for &[u8] { .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? }); } -impl SerializeCql for [u8; N] { +impl SerializeValue for [u8; N] { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Blob); writer @@ -307,7 +307,7 @@ impl SerializeCql for [u8; N] { .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? }); } -impl SerializeCql for IpAddr { +impl SerializeValue for IpAddr { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Inet); match me { @@ -316,7 +316,7 @@ impl SerializeCql for IpAddr { } }); } -impl SerializeCql for String { +impl SerializeValue for String { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Ascii, Text); writer @@ -324,7 +324,7 @@ impl SerializeCql for String { .map_err(|_| mk_ser_err::(typ, BuiltinSerializationErrorKind::SizeOverflow))? }); } -impl SerializeCql for Option { +impl SerializeValue for Option { fn serialize<'b>( &self, typ: &ColumnType, @@ -336,16 +336,16 @@ impl SerializeCql for Option { } } } -impl SerializeCql for Unset { +impl SerializeValue for Unset { impl_serialize_via_writer!(|_me, writer| writer.set_unset()); } -impl SerializeCql for Counter { +impl SerializeValue for Counter { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Counter); writer.set_value(me.0.to_be_bytes().as_slice()).unwrap() }); } -impl SerializeCql for CqlDuration { +impl SerializeValue for CqlDuration { impl_serialize_via_writer!(|me, typ, writer| { exact_type_check!(typ, Duration); // TODO: adjust vint_encode to use CellValueBuilder or something like that @@ -356,7 +356,7 @@ impl SerializeCql for CqlDuration { writer.set_value(buf.as_slice()).unwrap() }); } -impl SerializeCql for MaybeUnset { +impl SerializeValue for MaybeUnset { fn serialize<'b>( &self, typ: &ColumnType, @@ -368,7 +368,7 @@ impl SerializeCql for MaybeUnset { } } } -impl SerializeCql for &T { +impl SerializeValue for &T { fn serialize<'b>( &self, typ: &ColumnType, @@ -377,7 +377,7 @@ impl SerializeCql for &T { T::serialize(*self, typ, writer) } } -impl SerializeCql for Box { +impl SerializeValue for Box { fn serialize<'b>( &self, typ: &ColumnType, @@ -386,7 +386,7 @@ impl SerializeCql for Box { T::serialize(&**self, typ, writer) } } -impl SerializeCql for HashSet { +impl SerializeValue for HashSet { fn serialize<'b>( &self, typ: &ColumnType, @@ -401,7 +401,7 @@ impl SerializeCql for HashSet { ) } } -impl SerializeCql for HashMap { +impl SerializeValue for HashMap { fn serialize<'b>( &self, typ: &ColumnType, @@ -416,7 +416,7 @@ impl SerializeCql for HashMap< ) } } -impl SerializeCql for BTreeSet { +impl SerializeValue for BTreeSet { fn serialize<'b>( &self, typ: &ColumnType, @@ -431,7 +431,7 @@ impl SerializeCql for BTreeSet { ) } } -impl SerializeCql for BTreeMap { +impl SerializeValue for BTreeMap { fn serialize<'b>( &self, typ: &ColumnType, @@ -446,7 +446,7 @@ impl SerializeCql for BTreeMap { ) } } -impl SerializeCql for Vec { +impl SerializeValue for Vec { fn serialize<'b>( &self, typ: &ColumnType, @@ -461,7 +461,7 @@ impl SerializeCql for Vec { ) } } -impl<'a, T: SerializeCql + 'a> SerializeCql for &'a [T] { +impl<'a, T: SerializeValue + 'a> SerializeValue for &'a [T] { fn serialize<'b>( &self, typ: &ColumnType, @@ -476,7 +476,7 @@ impl<'a, T: SerializeCql + 'a> SerializeCql for &'a [T] { ) } } -impl SerializeCql for CqlValue { +impl SerializeValue for CqlValue { fn serialize<'b>( &self, typ: &ColumnType, @@ -498,14 +498,14 @@ fn serialize_cql_value<'b>( )); } match value { - CqlValue::Ascii(a) => <_ as SerializeCql>::serialize(&a, typ, writer), - CqlValue::Boolean(b) => <_ as SerializeCql>::serialize(&b, typ, writer), - CqlValue::Blob(b) => <_ as SerializeCql>::serialize(&b, typ, writer), - CqlValue::Counter(c) => <_ as SerializeCql>::serialize(&c, typ, writer), - CqlValue::Decimal(d) => <_ as SerializeCql>::serialize(&d, typ, writer), - CqlValue::Date(d) => <_ as SerializeCql>::serialize(&d, typ, writer), - CqlValue::Double(d) => <_ as SerializeCql>::serialize(&d, typ, writer), - CqlValue::Duration(d) => <_ as SerializeCql>::serialize(&d, typ, writer), + CqlValue::Ascii(a) => <_ as SerializeValue>::serialize(&a, typ, writer), + CqlValue::Boolean(b) => <_ as SerializeValue>::serialize(&b, typ, writer), + CqlValue::Blob(b) => <_ as SerializeValue>::serialize(&b, typ, writer), + CqlValue::Counter(c) => <_ as SerializeValue>::serialize(&c, typ, writer), + CqlValue::Decimal(d) => <_ as SerializeValue>::serialize(&d, typ, writer), + CqlValue::Date(d) => <_ as SerializeValue>::serialize(&d, typ, writer), + CqlValue::Double(d) => <_ as SerializeValue>::serialize(&d, typ, writer), + CqlValue::Duration(d) => <_ as SerializeValue>::serialize(&d, typ, writer), CqlValue::Empty => { if !typ.supports_special_empty_value() { return Err(mk_typck_err::( @@ -515,13 +515,13 @@ fn serialize_cql_value<'b>( } Ok(writer.set_value(&[]).unwrap()) } - CqlValue::Float(f) => <_ as SerializeCql>::serialize(&f, typ, writer), - CqlValue::Int(i) => <_ as SerializeCql>::serialize(&i, typ, writer), - CqlValue::BigInt(b) => <_ as SerializeCql>::serialize(&b, typ, writer), - CqlValue::Text(t) => <_ as SerializeCql>::serialize(&t, typ, writer), - CqlValue::Timestamp(t) => <_ as SerializeCql>::serialize(&t, typ, writer), - CqlValue::Inet(i) => <_ as SerializeCql>::serialize(&i, typ, writer), - CqlValue::List(l) => <_ as SerializeCql>::serialize(&l, typ, writer), + CqlValue::Float(f) => <_ as SerializeValue>::serialize(&f, typ, writer), + CqlValue::Int(i) => <_ as SerializeValue>::serialize(&i, typ, writer), + CqlValue::BigInt(b) => <_ as SerializeValue>::serialize(&b, typ, writer), + CqlValue::Text(t) => <_ as SerializeValue>::serialize(&t, typ, writer), + CqlValue::Timestamp(t) => <_ as SerializeValue>::serialize(&t, typ, writer), + CqlValue::Inet(i) => <_ as SerializeValue>::serialize(&i, typ, writer), + CqlValue::List(l) => <_ as SerializeValue>::serialize(&l, typ, writer), CqlValue::Map(m) => serialize_mapping( std::any::type_name::(), m.len(), @@ -529,16 +529,16 @@ fn serialize_cql_value<'b>( typ, writer, ), - CqlValue::Set(s) => <_ as SerializeCql>::serialize(&s, typ, writer), + CqlValue::Set(s) => <_ as SerializeValue>::serialize(&s, typ, writer), CqlValue::UserDefinedType { keyspace, type_name, fields, } => serialize_udt(typ, keyspace, type_name, fields, writer), - CqlValue::SmallInt(s) => <_ as SerializeCql>::serialize(&s, typ, writer), - CqlValue::TinyInt(t) => <_ as SerializeCql>::serialize(&t, typ, writer), - CqlValue::Time(t) => <_ as SerializeCql>::serialize(&t, typ, writer), - CqlValue::Timeuuid(t) => <_ as SerializeCql>::serialize(&t, typ, writer), + CqlValue::SmallInt(s) => <_ as SerializeValue>::serialize(&s, typ, writer), + CqlValue::TinyInt(t) => <_ as SerializeValue>::serialize(&t, typ, writer), + CqlValue::Time(t) => <_ as SerializeValue>::serialize(&t, typ, writer), + CqlValue::Timeuuid(t) => <_ as SerializeValue>::serialize(&t, typ, writer), CqlValue::Tuple(t) => { // We allow serializing tuples that have less fields // than the database tuple, but not the other way around. @@ -564,8 +564,8 @@ fn serialize_cql_value<'b>( }; serialize_tuple_like(typ, fields.iter(), t.iter(), writer) } - CqlValue::Uuid(u) => <_ as SerializeCql>::serialize(&u, typ, writer), - CqlValue::Varint(v) => <_ as SerializeCql>::serialize(&v, typ, writer), + CqlValue::Uuid(u) => <_ as SerializeValue>::serialize(&u, typ, writer), + CqlValue::Varint(v) => <_ as SerializeValue>::serialize(&v, typ, writer), } } @@ -717,7 +717,7 @@ macro_rules! impl_tuple { $($tidents:ident),*; $length:expr ) => { - impl<$($typs: SerializeCql),*> SerializeCql for ($($typs,)*) { + impl<$($typs: SerializeValue),*> SerializeValue for ($($typs,)*) { fn serialize<'b>( &self, typ: &ColumnType, @@ -743,7 +743,7 @@ macro_rules! impl_tuple { let mut builder = writer.into_value_builder(); let index = 0; $( - <$typs as SerializeCql>::serialize($fidents, $tidents, builder.make_sub_writer()) + <$typs as SerializeValue>::serialize($fidents, $tidents, builder.make_sub_writer()) .map_err(|err| mk_ser_err::( typ, TupleSerializationErrorKind::ElementSerializationFailed { @@ -792,7 +792,7 @@ impl_tuples!( 16 ); -fn serialize_sequence<'t, 'b, T: SerializeCql + 't>( +fn serialize_sequence<'t, 'b, T: SerializeValue + 't>( rust_name: &'static str, len: usize, iter: impl Iterator, @@ -836,7 +836,7 @@ fn serialize_sequence<'t, 'b, T: SerializeCql + 't>( .map_err(|_| mk_ser_err_named(rust_name, typ, BuiltinSerializationErrorKind::SizeOverflow)) } -fn serialize_mapping<'t, 'b, K: SerializeCql + 't, V: SerializeCql + 't>( +fn serialize_mapping<'t, 'b, K: SerializeValue + 't, V: SerializeValue + 't>( rust_name: &'static str, len: usize, iter: impl Iterator, @@ -883,17 +883,17 @@ fn serialize_mapping<'t, 'b, K: SerializeCql + 't, V: SerializeCql + 't>( .map_err(|_| mk_ser_err_named(rust_name, typ, BuiltinSerializationErrorKind::SizeOverflow)) } -/// Implements the [`SerializeCql`] trait for a type, provided that the type +/// Implements the [`SerializeValue`] trait for a type, provided that the type /// already implements the legacy [`Value`](crate::frame::value::Value) trait. /// /// # Note /// /// The translation from one trait to another encounters a performance penalty -/// and does not utilize the stronger guarantees of `SerializeCql`. Before +/// and does not utilize the stronger guarantees of `SerializeValue`. Before /// resorting to this macro, you should consider other options instead: /// /// - If the impl was generated using the `Value` procedural macro, you should -/// switch to the `SerializeCql` procedural macro. *The new macro behaves +/// switch to the `SerializeValue` procedural macro. *The new macro behaves /// differently by default, so please read its documentation first!* /// - If the impl was written by hand, it is still preferable to rewrite it /// manually. You have an opportunity to make your serialization logic @@ -930,7 +930,7 @@ fn serialize_mapping<'t, 'b, K: SerializeCql + 't, V: SerializeCql + 't>( #[macro_export] macro_rules! impl_serialize_cql_via_value { ($t:ident$(<$($targ:tt $(: $tbound:tt)?),*>)?) => { - impl $(<$($targ $(: $tbound)?),*>)? $crate::types::serialize::value::SerializeCql + impl $(<$($targ $(: $tbound)?),*>)? $crate::types::serialize::value::SerializeValue for $t$(<$($targ),*>)? where Self: $crate::frame::value::Value, @@ -949,13 +949,13 @@ macro_rules! impl_serialize_cql_via_value { }; } -/// Implements [`SerializeCql`] if the type wrapped over implements [`Value`]. +/// Implements [`SerializeValue`] if the type wrapped over implements [`Value`]. /// /// See the [`impl_serialize_cql_via_value`] macro on information about -/// the properties of the [`SerializeCql`] implementation. +/// the properties of the [`SerializeValue`] implementation. pub struct ValueAdapter(pub T); -impl SerializeCql for ValueAdapter +impl SerializeValue for ValueAdapter where T: Value, { @@ -981,7 +981,7 @@ where /// a properly encoded `[value]` as defined in the CQL protocol spec. /// /// See [`impl_serialize_cql_via_value`] which generates a boilerplate -/// [`SerializeCql`] implementation that uses this function. +/// [`SerializeValue`] implementation that uses this function. pub fn serialize_legacy_value<'b, T: Value>( v: &T, writer: CellWriter<'b>, @@ -989,13 +989,13 @@ pub fn serialize_legacy_value<'b, T: Value>( // It's an inefficient and slightly tricky but correct implementation. let mut buf = Vec::new(); ::serialize(v, &mut buf) - .map_err(|_| SerializationError::new(ValueToSerializeCqlAdapterError::TooBig))?; + .map_err(|_| SerializationError::new(ValueToSerializeValueAdapterError::TooBig))?; // Analyze the output. // All this dance shows how unsafe our previous interface was... if buf.len() < 4 { return Err(SerializationError(Arc::new( - ValueToSerializeCqlAdapterError::TooShort { size: buf.len() }, + ValueToSerializeValueAdapterError::TooShort { size: buf.len() }, ))); } @@ -1007,7 +1007,7 @@ pub fn serialize_legacy_value<'b, T: Value>( len if len >= 0 => { if contents.len() != len as usize { Err(SerializationError(Arc::new( - ValueToSerializeCqlAdapterError::DeclaredVsActualSizeMismatch { + ValueToSerializeValueAdapterError::DeclaredVsActualSizeMismatch { declared: len as usize, actual: contents.len(), }, @@ -1017,7 +1017,7 @@ pub fn serialize_legacy_value<'b, T: Value>( } } _ => Err(SerializationError(Arc::new( - ValueToSerializeCqlAdapterError::InvalidDeclaredSize { size: len }, + ValueToSerializeValueAdapterError::InvalidDeclaredSize { size: len }, ))), } } @@ -1465,9 +1465,9 @@ impl Display for UdtSerializationErrorKind { } /// Describes a failure to translate the output of the [`Value`] legacy trait -/// into an output of the [`SerializeCql`] trait. +/// into an output of the [`SerializeValue`] trait. #[derive(Error, Debug)] -pub enum ValueToSerializeCqlAdapterError { +pub enum ValueToSerializeValueAdapterError { /// The value is too bit to be serialized as it exceeds the maximum 2GB size limit. #[error("The value is too big to be serialized as it exceeds the maximum 2GB size limit")] TooBig, @@ -1512,17 +1512,17 @@ mod tests { use crate::types::serialize::{CellWriter, SerializationError}; use assert_matches::assert_matches; - use scylla_macros::SerializeCql; + use scylla_macros::SerializeValue; - use super::{SerializeCql, UdtSerializationErrorKind, UdtTypeCheckErrorKind}; + use super::{SerializeValue, UdtSerializationErrorKind, UdtTypeCheckErrorKind}; - fn check_compat(v: V) { + fn check_compat(v: V) { let mut legacy_data = Vec::new(); ::serialize(&v, &mut legacy_data).unwrap(); let mut new_data = Vec::new(); let new_data_writer = CellWriter::new(&mut new_data); - ::serialize(&v, &ColumnType::Int, new_data_writer).unwrap(); + ::serialize(&v, &ColumnType::Int, new_data_writer).unwrap(); assert_eq!(legacy_data, new_data); } @@ -1539,17 +1539,17 @@ mod tests { let v: i32 = 123; let mut typed_data = Vec::new(); let typed_data_writer = CellWriter::new(&mut typed_data); - <_ as SerializeCql>::serialize(&v, &ColumnType::Int, typed_data_writer).unwrap(); + <_ as SerializeValue>::serialize(&v, &ColumnType::Int, typed_data_writer).unwrap(); - let v = &v as &dyn SerializeCql; + let v = &v as &dyn SerializeValue; let mut erased_data = Vec::new(); let erased_data_writer = CellWriter::new(&mut erased_data); - <_ as SerializeCql>::serialize(&v, &ColumnType::Int, erased_data_writer).unwrap(); + <_ as SerializeValue>::serialize(&v, &ColumnType::Int, erased_data_writer).unwrap(); assert_eq!(typed_data, erased_data); } - fn do_serialize_result( + fn do_serialize_result( t: T, typ: &ColumnType, ) -> Result, SerializationError> { @@ -1558,11 +1558,11 @@ mod tests { t.serialize(typ, writer).map(|_| ()).map(|()| ret) } - fn do_serialize(t: T, typ: &ColumnType) -> Vec { + fn do_serialize(t: T, typ: &ColumnType) -> Vec { do_serialize_result(t, typ).unwrap() } - fn do_serialize_err(t: T, typ: &ColumnType) -> SerializationError { + fn do_serialize_err(t: T, typ: &ColumnType) -> SerializationError { do_serialize_result(t, typ).unwrap_err() } @@ -2016,11 +2016,11 @@ mod tests { // we properly ignore warnings about unused variables, unnecessary `mut`s // etc. that usually pop up when generating code for empty structs. #[allow(unused)] - #[derive(SerializeCql)] + #[derive(SerializeValue)] #[scylla(crate = crate)] struct TestUdtWithNoFields {} - #[derive(SerializeCql, Debug, PartialEq, Eq, Default)] + #[derive(SerializeValue, Debug, PartialEq, Eq, Default)] #[scylla(crate = crate)] struct TestUdtWithFieldSorting { a: String, @@ -2168,7 +2168,7 @@ mod tests { assert_eq!(result_normal, result_additional_field); } - #[derive(SerializeCql, Debug, PartialEq, Default)] + #[derive(SerializeValue, Debug, PartialEq, Default)] #[scylla(crate = crate)] struct TestUdtWithFieldSorting2 { a: String, @@ -2177,7 +2177,7 @@ mod tests { c: Vec, } - #[derive(SerializeCql, Debug, PartialEq, Default)] + #[derive(SerializeValue, Debug, PartialEq, Default)] #[scylla(crate = crate)] struct TestUdtWithFieldSorting3 { a: String, @@ -2276,9 +2276,9 @@ mod tests { ); } - #[derive(SerializeCql)] + #[derive(SerializeValue)] #[scylla(crate = crate)] - struct TestUdtWithGenerics<'a, T: SerializeCql> { + struct TestUdtWithGenerics<'a, T: SerializeValue> { a: &'a str, b: T, } @@ -2286,7 +2286,7 @@ mod tests { #[test] fn test_udt_serialization_with_generics() { // A minimal smoke test just to test that it works. - fn check_with_type(typ: ColumnType, t: T, cql_t: CqlValue) { + fn check_with_type(typ: ColumnType, t: T, cql_t: CqlValue) { let typ = ColumnType::UserDefinedType { type_name: "typ".to_string(), keyspace: "ks".to_string(), @@ -2320,7 +2320,7 @@ mod tests { check_with_type(ColumnType::Double, 123_f64, CqlValue::Double(123_f64)); } - #[derive(SerializeCql, Debug, PartialEq, Eq, Default)] + #[derive(SerializeValue, Debug, PartialEq, Eq, Default)] #[scylla(crate = crate, flavor = "enforce_order")] struct TestUdtWithEnforcedOrder { a: String, @@ -2422,7 +2422,7 @@ mod tests { let mut data = Vec::new(); - let err = <_ as SerializeCql>::serialize(&udt, &typ_not_udt, CellWriter::new(&mut data)) + let err = <_ as SerializeValue>::serialize(&udt, &typ_not_udt, CellWriter::new(&mut data)) .unwrap_err(); let err = err.0.downcast_ref::().unwrap(); assert_matches!( @@ -2445,7 +2445,7 @@ mod tests { }; let err = - <_ as SerializeCql>::serialize(&udt, &typ, CellWriter::new(&mut data)).unwrap_err(); + <_ as SerializeValue>::serialize(&udt, &typ, CellWriter::new(&mut data)).unwrap_err(); let err = err.0.downcast_ref::().unwrap(); assert_matches!( err.kind, @@ -2462,8 +2462,9 @@ mod tests { ], }; - let err = <_ as SerializeCql>::serialize(&udt, &typ_without_c, CellWriter::new(&mut data)) - .unwrap_err(); + let err = + <_ as SerializeValue>::serialize(&udt, &typ_without_c, CellWriter::new(&mut data)) + .unwrap_err(); let err = err.0.downcast_ref::().unwrap(); assert_matches!( err.kind, @@ -2482,9 +2483,12 @@ mod tests { ], }; - let err = - <_ as SerializeCql>::serialize(&udt, &typ_unexpected_field, CellWriter::new(&mut data)) - .unwrap_err(); + let err = <_ as SerializeValue>::serialize( + &udt, + &typ_unexpected_field, + CellWriter::new(&mut data), + ) + .unwrap_err(); let err = err.0.downcast_ref::().unwrap(); assert_matches!( err.kind, @@ -2494,7 +2498,7 @@ mod tests { ); } - #[derive(SerializeCql, Debug)] + #[derive(SerializeValue, Debug)] #[scylla(crate = crate)] struct TestUdtWithFieldRename { a: String, @@ -2502,7 +2506,7 @@ mod tests { b: i32, } - #[derive(SerializeCql, Debug)] + #[derive(SerializeValue, Debug)] #[scylla(crate = crate, flavor = "enforce_order")] struct TestUdtWithFieldRenameAndEnforceOrder { a: String, @@ -2575,7 +2579,7 @@ mod tests { } #[allow(unused)] - #[derive(SerializeCql, Debug)] + #[derive(SerializeValue, Debug)] #[scylla(crate = crate, flavor = "enforce_order", skip_name_checks)] struct TestUdtWithSkippedNameChecks { a: String, @@ -2614,7 +2618,7 @@ mod tests { assert_eq!(reference, udt); } - #[derive(SerializeCql, Debug, PartialEq, Eq, Default)] + #[derive(SerializeValue, Debug, PartialEq, Eq, Default)] #[scylla(crate = crate, force_exact_match)] struct TestStrictUdtWithFieldSorting { a: String, @@ -2676,7 +2680,7 @@ mod tests { ); } - #[derive(SerializeCql, Debug, PartialEq, Eq, Default)] + #[derive(SerializeValue, Debug, PartialEq, Eq, Default)] #[scylla(crate = crate, flavor = "enforce_order", force_exact_match)] struct TestStrictUdtWithEnforcedOrder { a: String, @@ -2704,9 +2708,12 @@ mod tests { ], }; - let err = - <_ as SerializeCql>::serialize(&udt, &typ_unexpected_field, CellWriter::new(&mut data)) - .unwrap_err(); + let err = <_ as SerializeValue>::serialize( + &udt, + &typ_unexpected_field, + CellWriter::new(&mut data), + ) + .unwrap_err(); let err = err.0.downcast_ref::().unwrap(); assert_matches!( err.kind, @@ -2714,7 +2721,7 @@ mod tests { ); } - #[derive(SerializeCql, Debug)] + #[derive(SerializeValue, Debug)] #[scylla(crate = crate, flavor = "enforce_order", skip_name_checks)] struct TestUdtWithSkippedFields { a: String, diff --git a/scylla-cql/src/types/serialize/writers.rs b/scylla-cql/src/types/serialize/writers.rs index 6587634a47..cfd36202bb 100644 --- a/scylla-cql/src/types/serialize/writers.rs +++ b/scylla-cql/src/types/serialize/writers.rs @@ -63,7 +63,7 @@ impl<'buf> RowWriter<'buf> { /// After the value is fully initialized, the handle is consumed and /// a [`WrittenCellProof`] object is returned /// in its stead. This is a type-level proof that the value was fully initialized -/// and is used in [`SerializeCql::serialize`](`super::value::SerializeCql::serialize`) +/// and is used in [`SerializeValue::serialize`](`super::value::SerializeValue::serialize`) /// in order to enforce the implementer to fully initialize the provided handle /// to CQL value. /// @@ -190,7 +190,7 @@ impl<'buf> CellValueBuilder<'buf> { /// the value is fully initialized and the `CellWriter` is destroyed. /// /// The purpose of this type is to enforce the contract of -/// [`SerializeCql::serialize`](super::value::SerializeCql::serialize): either +/// [`SerializeValue::serialize`](super::value::SerializeValue::serialize): either /// the method succeeds and returns a proof that it serialized itself /// into the given value, or it fails and returns an error or panics. #[derive(Debug)] diff --git a/scylla-macros/src/lib.rs b/scylla-macros/src/lib.rs index cb8b967c84..47103cae71 100644 --- a/scylla-macros/src/lib.rs +++ b/scylla-macros/src/lib.rs @@ -12,7 +12,7 @@ mod serialize; /// Documentation for this macro can only be found /// in `scylla` crate - not in scylla-macros nor in scylla-cql. /// This is because of rustdocs limitations that are hard to explain here. -#[proc_macro_derive(SerializeCql, attributes(scylla))] +#[proc_macro_derive(SerializeValue, attributes(scylla))] pub fn serialize_cql_derive(tokens_input: TokenStream) -> TokenStream { match serialize::cql::derive_serialize_cql(tokens_input) { Ok(t) => t.into_token_stream().into(), diff --git a/scylla-macros/src/serialize/cql.rs b/scylla-macros/src/serialize/cql.rs index 4302850213..0340433d6a 100644 --- a/scylla-macros/src/serialize/cql.rs +++ b/scylla-macros/src/serialize/cql.rs @@ -64,12 +64,12 @@ struct Context { pub(crate) fn derive_serialize_cql(tokens_input: TokenStream) -> Result { let input: syn::DeriveInput = syn::parse(tokens_input)?; let struct_name = input.ident.clone(); - let named_fields = crate::parser::parse_named_fields(&input, "SerializeCql")?; + let named_fields = crate::parser::parse_named_fields(&input, "SerializeValue")?; let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); let attributes = Attributes::from_attributes(&input.attrs)?; let crate_path = attributes.crate_path(); - let implemented_trait: syn::Path = parse_quote!(#crate_path::SerializeCql); + let implemented_trait: syn::Path = parse_quote!(#crate_path::SerializeValue); let fields = named_fields .named @@ -305,7 +305,7 @@ impl<'a> Generator for FieldSortingGenerator<'a> { #udt_field_names => { #serialize_missing_nulls_statement let sub_builder = #crate_path::CellValueBuilder::make_sub_writer(&mut builder); - match <#field_types as #crate_path::SerializeCql>::serialize(&self.#rust_field_idents, field_type, sub_builder) { + match <#field_types as #crate_path::SerializeValue>::serialize(&self.#rust_field_idents, field_type, sub_builder) { ::std::result::Result::Ok(_proof) => {} ::std::result::Result::Err(err) => { return ::std::result::Result::Err(mk_ser_err( @@ -412,7 +412,7 @@ impl<'a> Generator for FieldOrderedGenerator<'a> { Some((field_name, typ)) => { if #name_check_expression { let sub_builder = #crate_path::CellValueBuilder::make_sub_writer(&mut builder); - match <#typ as #crate_path::SerializeCql>::serialize(&self.#rust_field_ident, typ, sub_builder) { + match <#typ as #crate_path::SerializeValue>::serialize(&self.#rust_field_ident, typ, sub_builder) { Ok(_proof) => {}, Err(err) => { return ::std::result::Result::Err(mk_ser_err( diff --git a/scylla-macros/src/serialize/row.rs b/scylla-macros/src/serialize/row.rs index 948a71ab41..fd4649dc56 100644 --- a/scylla-macros/src/serialize/row.rs +++ b/scylla-macros/src/serialize/row.rs @@ -237,7 +237,7 @@ impl<'a> Generator for ColumnSortingGenerator<'a> { #( #udt_field_names => { let sub_writer = #crate_path::RowWriter::make_cell_writer(writer); - match <#field_types as #crate_path::SerializeCql>::serialize(&self.#rust_field_idents, &spec.typ, sub_writer) { + match <#field_types as #crate_path::SerializeValue>::serialize(&self.#rust_field_idents, &spec.typ, sub_writer) { ::std::result::Result::Ok(_proof) => {} ::std::result::Result::Err(err) => { return ::std::result::Result::Err(mk_ser_err( @@ -339,7 +339,7 @@ impl<'a> Generator for ColumnOrderedGenerator<'a> { Some(spec) => { if #name_check_expression { let cell_writer = #crate_path::RowWriter::make_cell_writer(writer); - match <#typ as #crate_path::SerializeCql>::serialize(&self.#rust_field_ident, &spec.typ, cell_writer) { + match <#typ as #crate_path::SerializeValue>::serialize(&self.#rust_field_ident, &spec.typ, cell_writer) { Ok(_proof) => {}, Err(err) => { return ::std::result::Result::Err(mk_ser_err( diff --git a/scylla/src/macros.rs b/scylla/src/macros.rs index 5c01bff053..0cb03c8632 100644 --- a/scylla/src/macros.rs +++ b/scylla/src/macros.rs @@ -24,7 +24,7 @@ pub use scylla_cql::macros::FromUserType; /// pub use scylla_cql::macros::IntoUserType; -/// Derive macro for the [`SerializeCql`](crate::serialize::value::SerializeCql) trait +/// Derive macro for the [`SerializeValue`](crate::serialize::value::SerializeValue) trait /// which serializes given Rust structure as a User Defined Type (UDT). /// /// At the moment, only structs with named fields are supported. @@ -57,8 +57,8 @@ pub use scylla_cql::macros::IntoUserType; /// ...can be serialized using the following struct: /// /// ```rust -/// # use scylla::SerializeCql; -/// #[derive(SerializeCql)] +/// # use scylla::SerializeValue; +/// #[derive(SerializeValue)] /// struct MyUdt { /// a: i32, /// b: Option, @@ -87,11 +87,11 @@ pub use scylla_cql::macros::IntoUserType; /// /// By default, the code generated by the derive macro will refer to the items /// defined by the driver (types, traits, etc.) via the `::scylla` path. -/// For example, it will refer to the [`SerializeCql`](crate::serialize::value::SerializeCql) trait +/// For example, it will refer to the [`SerializeValue`](crate::serialize::value::SerializeValue) trait /// using the following path: /// /// ```rust,ignore -/// use ::scylla::_macro_internal::SerializeCql; +/// use ::scylla::_macro_internal::SerializeValue; /// ``` /// /// Most users will simply add `scylla` to their dependencies, then use @@ -134,7 +134,7 @@ pub use scylla_cql::macros::IntoUserType; /// /// --- /// -pub use scylla_cql::macros::SerializeCql; +pub use scylla_cql::macros::SerializeValue; /// Derive macro for the [`SerializeRow`](crate::serialize::row::SerializeRow) trait /// which serializes given Rust structure into bind markers for a CQL statement. diff --git a/scylla/src/transport/cql_collections_test.rs b/scylla/src/transport/cql_collections_test.rs index 311cb36871..24f8ee51c4 100644 --- a/scylla/src/transport/cql_collections_test.rs +++ b/scylla/src/transport/cql_collections_test.rs @@ -2,7 +2,7 @@ use crate::cql_to_rust::FromCqlVal; use crate::test_utils::{create_new_session_builder, setup_tracing}; use crate::utils::test_utils::unique_keyspace_name; use crate::{frame::response::result::CqlValue, Session}; -use scylla_cql::types::serialize::value::SerializeCql; +use scylla_cql::types::serialize::value::SerializeValue; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; async fn connect() -> Session { @@ -33,7 +33,7 @@ async fn insert_and_select( to_insert: &InsertT, expected: &SelectT, ) where - InsertT: SerializeCql, + InsertT: SerializeValue, SelectT: FromCqlVal> + PartialEq + std::fmt::Debug, { session diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/transport/cql_types_test.rs index 8429a6ce0e..748e4ec199 100644 --- a/scylla/src/transport/cql_types_test.rs +++ b/scylla/src/transport/cql_types_test.rs @@ -8,8 +8,8 @@ use crate::transport::session::Session; use crate::utils::test_utils::unique_keyspace_name; use itertools::Itertools; use scylla_cql::frame::value::{CqlTimeuuid, CqlVarint}; -use scylla_cql::types::serialize::value::SerializeCql; -use scylla_macros::SerializeCql; +use scylla_cql::types::serialize::value::SerializeValue; +use scylla_macros::SerializeValue; use std::cmp::PartialEq; use std::fmt::Debug; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; @@ -64,7 +64,7 @@ async fn init_test(table_name: &str, type_name: &str) -> Session { // Expected values and bound values are computed using T::from_str async fn run_tests(tests: &[&str], type_name: &str) where - T: SerializeCql + FromCqlVal + FromStr + Debug + Clone + PartialEq, + T: SerializeValue + FromCqlVal + FromStr + Debug + Clone + PartialEq, { let session: Session = init_test(type_name, type_name).await; session.await_schema_agreement().await.unwrap(); @@ -1500,7 +1500,7 @@ async fn test_udt_after_schema_update() { .await .unwrap(); - #[derive(SerializeCql, FromUserType, Debug, PartialEq)] + #[derive(SerializeValue, FromUserType, Debug, PartialEq)] #[scylla(crate = crate)] struct UdtV1 { first: i32, @@ -1681,7 +1681,7 @@ async fn test_udt_with_missing_field() { element: TQ, expected: TR, ) where - TQ: SerializeCql, + TQ: SerializeValue, TR: FromCqlVal + PartialEq + Debug, { session @@ -1712,7 +1712,7 @@ async fn test_udt_with_missing_field() { fourth: Option>, } - #[derive(SerializeCql)] + #[derive(SerializeValue)] #[scylla(crate = crate)] struct UdtV1 { first: i32, @@ -1738,7 +1738,7 @@ async fn test_udt_with_missing_field() { id += 1; - #[derive(SerializeCql)] + #[derive(SerializeValue)] #[scylla(crate = crate)] struct UdtV2 { first: i32, @@ -1766,7 +1766,7 @@ async fn test_udt_with_missing_field() { id += 1; - #[derive(SerializeCql)] + #[derive(SerializeValue)] #[scylla(crate = crate)] struct UdtV3 { first: i32, @@ -1794,7 +1794,7 @@ async fn test_udt_with_missing_field() { id += 1; - #[derive(SerializeCql)] + #[derive(SerializeValue)] #[scylla(crate = crate, flavor="enforce_order")] struct UdtV4 { first: i32, diff --git a/scylla/src/transport/locator/tablets.rs b/scylla/src/transport/locator/tablets.rs index 9277ce1934..14a3ea2b32 100644 --- a/scylla/src/transport/locator/tablets.rs +++ b/scylla/src/transport/locator/tablets.rs @@ -585,7 +585,7 @@ mod tests { use std::sync::Arc; use scylla_cql::frame::response::result::{ColumnType, CqlValue, TableSpec}; - use scylla_cql::types::serialize::value::SerializeCql; + use scylla_cql::types::serialize::value::SerializeValue; use scylla_cql::types::serialize::CellWriter; use tracing::debug; use uuid::Uuid; @@ -639,7 +639,7 @@ mod tests { ]))), ]); - SerializeCql::serialize(&value, &col_type, CellWriter::new(&mut data)).unwrap(); + SerializeValue::serialize(&value, &col_type, CellWriter::new(&mut data)).unwrap(); debug!("{:?}", data); custom_payload.insert(CUSTOM_PAYLOAD_TABLETS_V1_KEY.to_string(), data); @@ -673,12 +673,13 @@ mod tests { ])), ]); - SerializeCql::serialize(&value, &RAW_TABLETS_CQL_TYPE, CellWriter::new(&mut data)).unwrap(); + SerializeValue::serialize(&value, &RAW_TABLETS_CQL_TYPE, CellWriter::new(&mut data)) + .unwrap(); tracing::debug!("{:?}", data); custom_payload.insert( CUSTOM_PAYLOAD_TABLETS_V1_KEY.to_string(), - // Skipping length because `SerializeCql::serialize` adds length at the + // Skipping length because `SerializeValue::serialize` adds length at the // start of serialized value while Scylla sends the value without initial // length. data[4..].to_vec(), diff --git a/scylla/src/transport/session_test.rs b/scylla/src/transport/session_test.rs index 8136477251..459312dd0c 100644 --- a/scylla/src/transport/session_test.rs +++ b/scylla/src/transport/session_test.rs @@ -30,7 +30,7 @@ use futures::{FutureExt, StreamExt, TryStreamExt}; use itertools::Itertools; use scylla_cql::frame::response::result::ColumnType; use scylla_cql::types::serialize::row::{SerializeRow, SerializedValues}; -use scylla_cql::types::serialize::value::SerializeCql; +use scylla_cql::types::serialize::value::SerializeValue; use std::collections::BTreeSet; use std::collections::{BTreeMap, HashMap}; use std::sync::atomic::{AtomicBool, Ordering}; @@ -1996,17 +1996,17 @@ async fn test_unusual_valuelists() { .await .unwrap(); - let values_dyn: Vec<&dyn SerializeCql> = vec![ - &1 as &dyn SerializeCql, - &2 as &dyn SerializeCql, - &"&dyn" as &dyn SerializeCql, + let values_dyn: Vec<&dyn SerializeValue> = vec![ + &1 as &dyn SerializeValue, + &2 as &dyn SerializeValue, + &"&dyn" as &dyn SerializeValue, ]; session.execute(&insert_a_b_c, values_dyn).await.unwrap(); - let values_box_dyn: Vec> = vec![ - Box::new(1) as Box, - Box::new(3) as Box, - Box::new("Box dyn") as Box, + let values_box_dyn: Vec> = vec![ + Box::new(1) as Box, + Box::new(3) as Box, + Box::new("Box dyn") as Box, ]; session .execute(&insert_a_b_c, values_box_dyn) diff --git a/scylla/tests/integration/hygiene.rs b/scylla/tests/integration/hygiene.rs index a3b400f474..622acf13d4 100644 --- a/scylla/tests/integration/hygiene.rs +++ b/scylla/tests/integration/hygiene.rs @@ -65,7 +65,7 @@ macro_rules! test_crate { } #[allow(unused)] - #[derive(_scylla::macros::SerializeCql, _scylla::macros::SerializeRow)] + #[derive(_scylla::macros::SerializeValue, _scylla::macros::SerializeRow)] #[scylla(crate = _scylla)] struct TestStructNew { x: ::core::primitive::i32, From 030da9a5181e2ca8b58b06d6d63c8dad8e4f4f03 Mon Sep 17 00:00:00 2001 From: muzarski Date: Tue, 14 May 2024 14:36:37 +0200 Subject: [PATCH 2/4] treewide: serialize_cql -> serialize_value --- scylla-cql/src/types/serialize/value.rs | 2 +- scylla-macros/src/lib.rs | 4 ++-- scylla-macros/src/serialize/cql.rs | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scylla-cql/src/types/serialize/value.rs b/scylla-cql/src/types/serialize/value.rs index 83b1e86068..b8b3f28be6 100644 --- a/scylla-cql/src/types/serialize/value.rs +++ b/scylla-cql/src/types/serialize/value.rs @@ -1535,7 +1535,7 @@ mod tests { } #[test] - fn test_dyn_serialize_cql() { + fn test_dyn_serialize_value() { let v: i32 = 123; let mut typed_data = Vec::new(); let typed_data_writer = CellWriter::new(&mut typed_data); diff --git a/scylla-macros/src/lib.rs b/scylla-macros/src/lib.rs index 47103cae71..0b6fd58ca2 100644 --- a/scylla-macros/src/lib.rs +++ b/scylla-macros/src/lib.rs @@ -13,8 +13,8 @@ mod serialize; /// in `scylla` crate - not in scylla-macros nor in scylla-cql. /// This is because of rustdocs limitations that are hard to explain here. #[proc_macro_derive(SerializeValue, attributes(scylla))] -pub fn serialize_cql_derive(tokens_input: TokenStream) -> TokenStream { - match serialize::cql::derive_serialize_cql(tokens_input) { +pub fn serialize_value_derive(tokens_input: TokenStream) -> TokenStream { + match serialize::cql::derive_serialize_value(tokens_input) { Ok(t) => t.into_token_stream().into(), Err(e) => e.into_compile_error().into(), } diff --git a/scylla-macros/src/serialize/cql.rs b/scylla-macros/src/serialize/cql.rs index 0340433d6a..8d2d72044d 100644 --- a/scylla-macros/src/serialize/cql.rs +++ b/scylla-macros/src/serialize/cql.rs @@ -61,7 +61,9 @@ struct Context { fields: Vec, } -pub(crate) fn derive_serialize_cql(tokens_input: TokenStream) -> Result { +pub(crate) fn derive_serialize_value( + tokens_input: TokenStream, +) -> Result { let input: syn::DeriveInput = syn::parse(tokens_input)?; let struct_name = input.ident.clone(); let named_fields = crate::parser::parse_named_fields(&input, "SerializeValue")?; From d518c141a9a6fd0b339b31645f19e992125dbba8 Mon Sep 17 00:00:00 2001 From: muzarski Date: Tue, 14 May 2024 14:43:43 +0200 Subject: [PATCH 3/4] treewide: impl_serialize_cql_via_value -> impl_serialize_value_via_value --- docs/source/migration-guides/0.11-serialization.md | 2 +- scylla-cql/src/types/serialize/value.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/source/migration-guides/0.11-serialization.md b/docs/source/migration-guides/0.11-serialization.md index 36a264004d..77004b03de 100644 --- a/docs/source/migration-guides/0.11-serialization.md +++ b/docs/source/migration-guides/0.11-serialization.md @@ -100,7 +100,7 @@ Conversion in the other direction is not possible. It is possible to directly generate an `impl` of `SerializeRow` and `SerializeValue` on a type which implements, respectively, `ValueList` or `Value`, without using the wrappers from the previous section. The following macros are provided: -- `impl_serialize_cql_via_value` - implements `SerializeValue` if the type wrapped over implements `Value`, +- `impl_serialize_value_via_value` - implements `SerializeValue` if the type wrapped over implements `Value`, - `impl_serialize_row_via_value_list` - implements `SerializeRow` if the type wrapped over implements `ValueList`, The implementations are practically as those generated by the wrappers described in the previous section. diff --git a/scylla-cql/src/types/serialize/value.rs b/scylla-cql/src/types/serialize/value.rs index b8b3f28be6..5ef6c8c6a8 100644 --- a/scylla-cql/src/types/serialize/value.rs +++ b/scylla-cql/src/types/serialize/value.rs @@ -906,14 +906,14 @@ fn serialize_mapping<'t, 'b, K: SerializeValue + 't, V: SerializeValue + 't>( /// /// ```rust /// # use scylla_cql::frame::value::{Value, ValueTooBig}; -/// # use scylla_cql::impl_serialize_cql_via_value; +/// # use scylla_cql::impl_serialize_value_via_value; /// struct NoGenerics {} /// impl Value for NoGenerics { /// fn serialize<'b>(&self, _buf: &mut Vec) -> Result<(), ValueTooBig> { /// Ok(()) /// } /// } -/// impl_serialize_cql_via_value!(NoGenerics); +/// impl_serialize_value_via_value!(NoGenerics); /// /// // Generic types are also supported. You must specify the bounds if the /// // struct/enum contains any. @@ -925,10 +925,10 @@ fn serialize_mapping<'t, 'b, K: SerializeValue + 't, V: SerializeValue + 't>( /// Ok(()) /// } /// } -/// impl_serialize_cql_via_value!(WithGenerics); +/// impl_serialize_value_via_value!(WithGenerics); /// ``` #[macro_export] -macro_rules! impl_serialize_cql_via_value { +macro_rules! impl_serialize_value_via_value { ($t:ident$(<$($targ:tt $(: $tbound:tt)?),*>)?) => { impl $(<$($targ $(: $tbound)?),*>)? $crate::types::serialize::value::SerializeValue for $t$(<$($targ),*>)? @@ -951,7 +951,7 @@ macro_rules! impl_serialize_cql_via_value { /// Implements [`SerializeValue`] if the type wrapped over implements [`Value`]. /// -/// See the [`impl_serialize_cql_via_value`] macro on information about +/// See the [`impl_serialize_value_via_value`] macro on information about /// the properties of the [`SerializeValue`] implementation. pub struct ValueAdapter(pub T); @@ -980,7 +980,7 @@ where /// Returns an error if the result of the `Value::serialize` call was not /// a properly encoded `[value]` as defined in the CQL protocol spec. /// -/// See [`impl_serialize_cql_via_value`] which generates a boilerplate +/// See [`impl_serialize_value_via_value`] which generates a boilerplate /// [`SerializeValue`] implementation that uses this function. pub fn serialize_legacy_value<'b, T: Value>( v: &T, From 7440d3d1d516f839abc6436abc626540543eb03a Mon Sep 17 00:00:00 2001 From: muzarski Date: Wed, 15 May 2024 13:53:42 +0200 Subject: [PATCH 4/4] macros: rename module cql to value --- scylla-macros/src/lib.rs | 2 +- scylla-macros/src/serialize/mod.rs | 2 +- scylla-macros/src/serialize/{cql.rs => value.rs} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename scylla-macros/src/serialize/{cql.rs => value.rs} (100%) diff --git a/scylla-macros/src/lib.rs b/scylla-macros/src/lib.rs index 0b6fd58ca2..5022f09f15 100644 --- a/scylla-macros/src/lib.rs +++ b/scylla-macros/src/lib.rs @@ -14,7 +14,7 @@ mod serialize; /// This is because of rustdocs limitations that are hard to explain here. #[proc_macro_derive(SerializeValue, attributes(scylla))] pub fn serialize_value_derive(tokens_input: TokenStream) -> TokenStream { - match serialize::cql::derive_serialize_value(tokens_input) { + match serialize::value::derive_serialize_value(tokens_input) { Ok(t) => t.into_token_stream().into(), Err(e) => e.into_compile_error().into(), } diff --git a/scylla-macros/src/serialize/mod.rs b/scylla-macros/src/serialize/mod.rs index 28c8b91097..b9c1fa9853 100644 --- a/scylla-macros/src/serialize/mod.rs +++ b/scylla-macros/src/serialize/mod.rs @@ -1,7 +1,7 @@ use darling::FromMeta; -pub(crate) mod cql; pub(crate) mod row; +pub(crate) mod value; #[derive(Copy, Clone, PartialEq, Eq, Default)] enum Flavor { diff --git a/scylla-macros/src/serialize/cql.rs b/scylla-macros/src/serialize/value.rs similarity index 100% rename from scylla-macros/src/serialize/cql.rs rename to scylla-macros/src/serialize/value.rs