Skip to content

Commit 4c77b9b

Browse files
committed
treewide: SerializeCql -> SerializeValue
Replaced all occurrences of SerializeCql with SerializeValue.
1 parent 5dbb10b commit 4c77b9b

File tree

19 files changed

+224
-217
lines changed

19 files changed

+224
-217
lines changed

docs/source/data-types/udt.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ CREATE TYPE ks.my_type (int_val int, text_val text)
99
```
1010

1111
To use this type in the driver, create a matching struct and derive:
12-
- `SerializeCql`: in order to be able to use this struct in query parameters. \
12+
- `SerializeValue`: in order to be able to use this struct in query parameters. \
1313
This macro requires fields of UDT and struct to have matching names, but the order
1414
of the fields is not required to be the same. \
15-
Note: you can use different name using `rename` attribute - see `SerializeCql` macro documentation.
15+
Note: you can use different name using `rename` attribute - see `SerializeValue` macro documentation.
1616
- `FromUserType`: in order to be able to use this struct in query results. \
1717
This macro requires fields of UDT and struct to be in the same *ORDER*. \
18-
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.
18+
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.
1919

2020
```rust
2121
# extern crate scylla;
2222
# async fn check_only_compiles() {
23-
use scylla::macros::{FromUserType, SerializeCql};
23+
use scylla::macros::{FromUserType, SerializeValue};
2424

2525
// Define a custom struct that matches the User Defined Type created earlier.
2626
// Fields must be in the same order as they are in the database and also
2727
// have the same names.
2828
// Wrapping a field in Option will gracefully handle null field values.
29-
#[derive(Debug, FromUserType, SerializeCql)]
29+
#[derive(Debug, FromUserType, SerializeValue)]
3030
struct MyType {
3131
int_val: i32,
3232
text_val: Option<String>,
@@ -41,7 +41,7 @@ struct MyType {
4141
> ***Important***\
4242
> For serialization, by default fields in the Rust struct must be defined with the same names as they are in the database.
4343
> The driver will serialize the fields in the order defined by the UDT, matching Rust fields by name.
44-
> You can change this behaviour using macro attributes, see `SerializeCql` macro documentation for more information.
44+
> You can change this behaviour using macro attributes, see `SerializeValue` macro documentation for more information.
4545
4646
Now it can be sent and received just like any other CQL value:
4747
```rust
@@ -50,10 +50,10 @@ Now it can be sent and received just like any other CQL value:
5050
# use std::error::Error;
5151
# async fn check_only_compiles(session: &Session) -> Result<(), Box<dyn Error>> {
5252
use scylla::IntoTypedRows;
53-
use scylla::macros::{FromUserType, SerializeCql};
53+
use scylla::macros::{FromUserType, SerializeValue};
5454
use scylla::cql_to_rust::FromCqlVal;
5555

56-
#[derive(Debug, FromUserType, SerializeCql)]
56+
#[derive(Debug, FromUserType, SerializeValue)]
5757
struct MyType {
5858
int_val: i32,
5959
text_val: Option<String>,

docs/source/migration-guides/0.11-serialization.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,31 @@ In version 0.11, a new set of traits is introduced and the old ones are deprecat
2828

2929
Both the old and the new APIs are based on three core traits:
3030

31-
- `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.
31+
- `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.
3232
- `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`.
3333
- `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.
3434

3535
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`.
3636

37-
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.
37+
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.
3838

3939
## Migration scenarios
4040

41-
### Different default behavior in `SerializeRow`/`SerializeCql` macros
41+
### Different default behavior in `SerializeRow`/`SerializeValue` macros
4242

43-
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.
43+
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.
4444

4545
> **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.
4646
4747
In order to bring the old behavior to the new macros (the only difference being type checking which cannot be disabled right now) you can configure it using attributes, as shown in the snippet below:
4848

4949
```rust
5050
# extern crate scylla;
51-
use scylla::SerializeCql;
51+
use scylla::SerializeValue;
5252

5353
// The exact same attributes apply to the `SerializeRow` macro and their
5454
// effect is completely analogous.
55-
#[derive(SerializeCql)]
55+
#[derive(SerializeValue)]
5656
#[scylla(flavor = "enforce_order", skip_name_checks)]
5757
struct Person {
5858
name: String,
@@ -61,7 +61,7 @@ struct Person {
6161
}
6262
```
6363

64-
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.
64+
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.
6565

6666
### Preparing is mandatory with a non-empty list of values
6767

@@ -80,13 +80,13 @@ In both cases, if the additional roundtrips are unacceptable, you should prepare
8080

8181
### Migrating from old to new traits *gradually*
8282

83-
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.
83+
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.
8484

8585
#### Converting an object implementing an old trait to a new trait
8686

8787
We provide a number of newtype wrappers:
8888

89-
- `ValueAdapter` - implements `SerializeCql` if the type wrapped over implements `Value`,
89+
- `ValueAdapter` - implements `SerializeValue` if the type wrapped over implements `Value`,
9090
- `ValueListAdapter` - implements `SerializeRow` if the type wrapped over implements `ValueList`,
9191
- `LegacyBatchValuesAdapter` - implements `BatchValues` if the type wrapped over implements `LegacyBatchValues`.
9292

@@ -98,9 +98,9 @@ Conversion in the other direction is not possible.
9898

9999
#### Custom implementations of old traits
100100

101-
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:
101+
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:
102102

103-
- `impl_serialize_cql_via_value` - implements `SerializeCql` if the type wrapped over implements `Value`,
103+
- `impl_serialize_cql_via_value` - implements `SerializeValue` if the type wrapped over implements `Value`,
104104
- `impl_serialize_row_via_value_list` - implements `SerializeRow` if the type wrapped over implements `ValueList`,
105105

106106
The implementations are practically as those generated by the wrappers described in the previous section.

examples/user-defined-type.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
22
use scylla::macros::FromUserType;
3-
use scylla::{SerializeCql, Session, SessionBuilder};
3+
use scylla::{SerializeValue, Session, SessionBuilder};
44
use std::env;
55

66
#[tokio::main]
@@ -29,7 +29,7 @@ async fn main() -> Result<()> {
2929

3030
// Define custom struct that matches User Defined Type created earlier
3131
// wrapping field in Option will gracefully handle null field values
32-
#[derive(Debug, FromUserType, SerializeCql)]
32+
#[derive(Debug, FromUserType, SerializeValue)]
3333
struct MyType {
3434
int_val: i32,
3535
text_val: Option<String>,

examples/value_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async fn main() {
4040

4141
// You can also use type generics:
4242
#[derive(scylla::SerializeRow)]
43-
struct MyTypeWithGenerics<S: scylla::serialize::value::SerializeCql> {
43+
struct MyTypeWithGenerics<S: scylla::serialize::value::SerializeValue> {
4444
k: i32,
4545
my: Option<S>,
4646
}

scylla-cql/src/frame/value_tests.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::frame::value::{CqlTimeuuid, CqlVarint};
22
use crate::frame::{response::result::CqlValue, types::RawValue, value::LegacyBatchValuesIterator};
33
use crate::types::serialize::batch::{BatchValues, BatchValuesIterator, LegacyBatchValuesAdapter};
44
use crate::types::serialize::row::{RowSerializationContext, SerializeRow};
5-
use crate::types::serialize::value::SerializeCql;
5+
use crate::types::serialize::value::SerializeValue;
66
use crate::types::serialize::{CellWriter, RowWriter};
77

88
use super::response::result::{ColumnSpec, ColumnType, TableSpec};
@@ -23,24 +23,24 @@ use uuid::Uuid;
2323

2424
fn serialized<T>(val: T, typ: ColumnType) -> Vec<u8>
2525
where
26-
T: Value + SerializeCql,
26+
T: Value + SerializeValue,
2727
{
2828
let mut result: Vec<u8> = Vec::new();
2929
Value::serialize(&val, &mut result).unwrap();
3030

3131
let mut new_result: Vec<u8> = Vec::new();
3232
let writer = CellWriter::new(&mut new_result);
33-
SerializeCql::serialize(&val, &typ, writer).unwrap();
33+
SerializeValue::serialize(&val, &typ, writer).unwrap();
3434

3535
assert_eq!(result, new_result);
3636

3737
result
3838
}
3939

40-
fn serialized_only_new<T: SerializeCql>(val: T, typ: ColumnType) -> Vec<u8> {
40+
fn serialized_only_new<T: SerializeValue>(val: T, typ: ColumnType) -> Vec<u8> {
4141
let mut result: Vec<u8> = Vec::new();
4242
let writer = CellWriter::new(&mut result);
43-
SerializeCql::serialize(&val, &typ, writer).unwrap();
43+
SerializeValue::serialize(&val, &typ, writer).unwrap();
4444
result
4545
}
4646

@@ -169,7 +169,7 @@ fn varint_test_cases_from_spec() -> Vec<(i64, Vec<u8>)> {
169169
#[cfg(any(feature = "num-bigint-03", feature = "num-bigint-04"))]
170170
fn generic_num_bigint_serialization<B>()
171171
where
172-
B: From<i64> + Value + SerializeCql,
172+
B: From<i64> + Value + SerializeValue,
173173
{
174174
let cases_from_the_spec: &[(i64, Vec<u8>)] = &varint_test_cases_from_spec();
175175

@@ -824,7 +824,7 @@ fn cqlvalue_serialization() {
824824
]
825825
);
826826

827-
// Unlike the legacy Value trait, SerializeCql takes case of reordering
827+
// Unlike the legacy Value trait, SerializeValue takes case of reordering
828828
// the fields
829829
let udt = CqlValue::UserDefinedType {
830830
keyspace: "ks".to_string(),

scylla-cql/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ pub mod macros {
55
pub use scylla_macros::FromRow;
66
pub use scylla_macros::FromUserType;
77
pub use scylla_macros::IntoUserType;
8-
pub use scylla_macros::SerializeCql;
98
pub use scylla_macros::SerializeRow;
9+
pub use scylla_macros::SerializeValue;
1010
pub use scylla_macros::ValueList;
1111

1212
// Reexports for derive(IntoUserType)
@@ -44,7 +44,7 @@ pub mod _macro_internal {
4444
BuiltinSerializationError as BuiltinTypeSerializationError,
4545
BuiltinSerializationErrorKind as BuiltinTypeSerializationErrorKind,
4646
BuiltinTypeCheckError as BuiltinTypeTypeCheckError,
47-
BuiltinTypeCheckErrorKind as BuiltinTypeTypeCheckErrorKind, SerializeCql,
47+
BuiltinTypeCheckErrorKind as BuiltinTypeTypeCheckErrorKind, SerializeValue,
4848
UdtSerializationErrorKind, UdtTypeCheckErrorKind,
4949
};
5050
pub use crate::types::serialize::writers::WrittenCellProof;

scylla-cql/src/types/serialize/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ pub use writers::{CellValueBuilder, CellWriter, RowWriter};
2424
/// one of types with an impl built into the driver fails. It is also returned
2525
/// from impls generated by the `SerializeRow` macro.
2626
/// - [`value::BuiltinSerializationError`] is analogous to the above but is
27-
/// returned from [`SerializeCql::serialize`](value::SerializeCql::serialize)
27+
/// returned from [`SerializeValue::serialize`](value::SerializeValue::serialize)
2828
/// instead both in the case of builtin impls and impls generated by the
29-
/// `SerializeCql` macro. It won't be returned by the `Session` directly,
29+
/// `SerializeValue` macro. It won't be returned by the `Session` directly,
3030
/// but it might be nested in the [`row::BuiltinSerializationError`].
3131
/// - [`row::ValueListToSerializeRowAdapterError`] is returned in case when
3232
/// a list of named values encoded with the legacy `ValueList` trait is passed

0 commit comments

Comments
 (0)