Skip to content

Commit

Permalink
Merge pull request #1176 from Lorak-mmk/migrate-higiene-test
Browse files Browse the repository at this point in the history
Hygiene fixes for ser / deser macros
  • Loading branch information
wprzytula authored Jan 27, 2025
2 parents ecc7fe6 + 361ec7e commit bb824b6
Show file tree
Hide file tree
Showing 46 changed files with 808 additions and 584 deletions.
728 changes: 362 additions & 366 deletions Cargo.lock.msrv

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scylla-cql/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use scylla_cql::frame::request::query::PagingState;
use scylla_cql::frame::request::SerializableRequest;
use scylla_cql::frame::response::result::ColumnType;
use scylla_cql::frame::{request::query, Compression, SerializedRequest};
use scylla_cql::types::serialize::row::SerializedValues;
use scylla_cql::serialize::row::SerializedValues;

fn make_query(contents: &str, values: SerializedValues) -> query::Query<'_> {
query::Query {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<'frame> FrameSlice<'frame> {
///
/// If the operation fails then the slice remains unchanged.
#[inline]
pub(super) fn read_cql_bytes(
pub fn read_cql_bytes(
&mut self,
) -> Result<Option<FrameSlice<'frame>>, LowLevelDeserializationError> {
// We copy the slice reference, not to mutate the FrameSlice in case of an error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
//!
//! ```rust
//! # use scylla_cql::frame::response::result::ColumnType;
//! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
//! # use scylla_cql::types::deserialize::value::DeserializeValue;
//! # use scylla_cql::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
//! # use scylla_cql::deserialize::value::DeserializeValue;
//! use thiserror::Error;
//! struct MyVec(Vec<u8>);
//! #[derive(Debug, Error)]
Expand Down Expand Up @@ -129,8 +129,8 @@
//!
//! ```rust
//! # use scylla_cql::frame::response::result::ColumnType;
//! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
//! # use scylla_cql::types::deserialize::value::DeserializeValue;
//! # use scylla_cql::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
//! # use scylla_cql::deserialize::value::DeserializeValue;
//! use thiserror::Error;
//! struct MySlice<'a>(&'a [u8]);
//! #[derive(Debug, Error)]
Expand Down Expand Up @@ -180,8 +180,8 @@
//!
//! ```rust
//! # use scylla_cql::frame::response::result::ColumnType;
//! # use scylla_cql::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
//! # use scylla_cql::types::deserialize::value::DeserializeValue;
//! # use scylla_cql::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
//! # use scylla_cql::deserialize::value::DeserializeValue;
//! # use bytes::Bytes;
//! use thiserror::Error;
//! struct MyBytes(Bytes);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ impl<'frame, 'metadata> ColumnIterator<'frame, 'metadata> {
/// - `specs` - information about columns of the serialized response,
/// - `slice` - a [FrameSlice] which points to the serialized row.
#[inline]
pub(crate) fn new(
specs: &'metadata [ColumnSpec<'metadata>],
slice: FrameSlice<'frame>,
) -> Self {
pub fn new(specs: &'metadata [ColumnSpec<'metadata>], slice: FrameSlice<'frame>) -> Self {
Self {
specs: specs.iter().enumerate(),
slice,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use assert_matches::assert_matches;
use bytes::Bytes;
use scylla_macros::DeserializeRow;

use crate::deserialize::row::BuiltinDeserializationErrorKind;
use crate::deserialize::{value, DeserializationError, FrameSlice};
use crate::frame::response::result::{ColumnSpec, ColumnType, TableSpec};
use crate::types::deserialize::row::BuiltinDeserializationErrorKind;
use crate::types::deserialize::{value, DeserializationError, FrameSlice};

use super::super::tests::{serialize_cells, spec};
use super::{BuiltinDeserializationError, ColumnIterator, CqlValue, DeserializeRow, Row};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::fmt::Debug;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};

use crate::deserialize::value::{TupleDeserializationErrorKind, TupleTypeCheckErrorKind};
use crate::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
use crate::frame::response::result::{ColumnType, CqlValue};
use crate::frame::value::{
Counter, CqlDate, CqlDecimal, CqlDecimalBorrowed, CqlDuration, CqlTime, CqlTimestamp,
CqlTimeuuid, CqlVarint, CqlVarintBorrowed,
};
use crate::types::deserialize::value::{TupleDeserializationErrorKind, TupleTypeCheckErrorKind};
use crate::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
use crate::types::serialize::value::SerializeValue;
use crate::types::serialize::CellWriter;
use crate::serialize::value::SerializeValue;
use crate::serialize::CellWriter;

use super::{
mk_deser_err, BuiltinDeserializationError, BuiltinDeserializationErrorKind,
Expand Down
20 changes: 9 additions & 11 deletions scylla-cql/src/frame/request/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ use bytes::{Buf, BufMut};
use std::{borrow::Cow, convert::TryInto, num::TryFromIntError};
use thiserror::Error;

use crate::{
frame::{
frame_errors::CqlRequestSerializationError,
request::{RequestOpcode, SerializableRequest},
types::{self, SerialConsistency},
},
types::serialize::{
raw_batch::{RawBatchValues, RawBatchValuesIterator},
row::SerializedValues,
RowWriter, SerializationError,
},
use crate::frame::{
frame_errors::CqlRequestSerializationError,
request::{RequestOpcode, SerializableRequest},
types::{self, SerialConsistency},
};
use crate::serialize::{
raw_batch::{RawBatchValues, RawBatchValuesIterator},
row::SerializedValues,
RowWriter, SerializationError,
};

use super::{DeserializableRequest, RequestDeserializationError};
Expand Down
4 changes: 2 additions & 2 deletions scylla-cql/src/frame/request/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod startup;
use batch::BatchTypeParseError;
use thiserror::Error;

use crate::types::serialize::row::SerializedValues;
use crate::serialize::row::SerializedValues;
use crate::Consistency;
use bytes::Bytes;

Expand Down Expand Up @@ -185,6 +185,7 @@ mod tests {

use bytes::Bytes;

use crate::serialize::row::SerializedValues;
use crate::{
frame::{
request::{
Expand All @@ -196,7 +197,6 @@ mod tests {
response::result::ColumnType,
types::{self, SerialConsistency},
},
types::serialize::row::SerializedValues,
Consistency,
};

Expand Down
6 changes: 2 additions & 4 deletions scylla-cql/src/frame/request/query.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::{borrow::Cow, num::TryFromIntError, ops::ControlFlow, sync::Arc};

use crate::{
frame::{frame_errors::CqlRequestSerializationError, types::SerialConsistency},
types::serialize::row::SerializedValues,
};
use crate::frame::{frame_errors::CqlRequestSerializationError, types::SerialConsistency};
use crate::serialize::row::SerializedValues;
use bytes::{Buf, BufMut};
use thiserror::Error;

Expand Down
12 changes: 6 additions & 6 deletions scylla-cql/src/frame/response/result.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#[allow(deprecated)]
use crate::cql_to_rust::{FromRow, FromRowError};
use crate::deserialize::result::{RawRowIterator, TypedRowIterator};
use crate::deserialize::row::DeserializeRow;
use crate::deserialize::value::{
mk_deser_err, BuiltinDeserializationErrorKind, DeserializeValue, MapIterator, UdtIterator,
};
use crate::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
use crate::frame::frame_errors::{
ColumnSpecParseError, ColumnSpecParseErrorKind, CqlResultParseError, CqlTypeParseError,
LowLevelDeserializationError, PreparedMetadataParseError, PreparedParseError,
Expand All @@ -13,12 +19,6 @@ use crate::frame::types;
use crate::frame::value::{
Counter, CqlDate, CqlDecimal, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint,
};
use crate::types::deserialize::result::{RawRowIterator, TypedRowIterator};
use crate::types::deserialize::row::DeserializeRow;
use crate::types::deserialize::value::{
mk_deser_err, BuiltinDeserializationErrorKind, DeserializeValue, MapIterator, UdtIterator,
};
use crate::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
use bytes::{Buf, Bytes};
use std::borrow::Cow;
use std::fmt::Debug;
Expand Down
8 changes: 4 additions & 4 deletions scylla-cql/src/frame/value_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

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::SerializeValue;
use crate::types::serialize::{CellWriter, RowWriter};
use crate::serialize::batch::{BatchValues, BatchValuesIterator, LegacyBatchValuesAdapter};
use crate::serialize::row::{RowSerializationContext, SerializeRow};
use crate::serialize::value::SerializeValue;
use crate::serialize::{CellWriter, RowWriter};

use super::response::result::{ColumnSpec, ColumnType, TableSpec};
use super::value::{
Expand Down
22 changes: 12 additions & 10 deletions scylla-cql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pub mod macros {
pub use crate::impl_serialize_value_via_value;
}

pub mod types;
pub mod deserialize;
pub mod serialize;

pub use crate::frame::response::cql_to_rust;
#[allow(deprecated)]
Expand All @@ -43,15 +44,15 @@ pub mod _macro_internal {
};
pub use crate::macros::*;

pub use crate::types::deserialize::row::{
pub use crate::deserialize::row::{
deser_error_replace_rust_name as row_deser_error_replace_rust_name,
mk_deser_err as mk_row_deser_err, mk_typck_err as mk_row_typck_err,
BuiltinDeserializationError as BuiltinRowDeserializationError,
BuiltinDeserializationErrorKind as BuiltinRowDeserializationErrorKind,
BuiltinTypeCheckErrorKind as DeserBuiltinRowTypeCheckErrorKind, ColumnIterator,
DeserializeRow,
};
pub use crate::types::deserialize::value::{
pub use crate::deserialize::value::{
deser_error_replace_rust_name as value_deser_error_replace_rust_name,
mk_deser_err as mk_value_deser_err, mk_typck_err as mk_value_typck_err,
BuiltinDeserializationError as BuiltinTypeDeserializationError,
Expand All @@ -60,23 +61,24 @@ pub mod _macro_internal {
UdtDeserializationErrorKind, UdtIterator,
UdtTypeCheckErrorKind as DeserUdtTypeCheckErrorKind,
};
pub use crate::types::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
pub use crate::types::serialize::row::{
pub use crate::deserialize::{DeserializationError, FrameSlice, TypeCheckError};
pub use crate::serialize::row::{
BuiltinSerializationError as BuiltinRowSerializationError,
BuiltinSerializationErrorKind as BuiltinRowSerializationErrorKind,
BuiltinTypeCheckError as BuiltinRowTypeCheckError,
BuiltinTypeCheckErrorKind as BuiltinRowTypeCheckErrorKind, RowSerializationContext,
SerializeRow,
};
pub use crate::types::serialize::value::{
pub use crate::serialize::value::{
BuiltinSerializationError as BuiltinTypeSerializationError,
BuiltinSerializationErrorKind as BuiltinTypeSerializationErrorKind,
BuiltinTypeCheckError as BuiltinTypeTypeCheckError,
BuiltinTypeCheckErrorKind as BuiltinTypeTypeCheckErrorKind, SerializeValue,
UdtSerializationErrorKind, UdtTypeCheckErrorKind,
};
pub use crate::types::serialize::writers::WrittenCellProof;
pub use crate::types::serialize::{
CellValueBuilder, CellWriter, RowWriter, SerializationError,
};
pub use crate::serialize::writers::WrittenCellProof;
pub use crate::serialize::{CellValueBuilder, CellWriter, RowWriter, SerializationError};
}

#[cfg(test)]
mod types_tests;
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ impl<'a> RowSerializationContext<'a> {
}
}

/// Creates the serialization context directly from column specs.
#[inline]
pub fn from_specs(specs: &'a [ColumnSpec<'a>]) -> Self {
Self { columns: specs }
}

/// Constructs an empty `RowSerializationContext`, as if for a statement
/// with no bind markers.
#[inline]
Expand Down Expand Up @@ -418,17 +424,17 @@ impl_tuples!(
#[macro_export]
macro_rules! impl_serialize_row_via_value_list {
($t:ident$(<$($targ:tt $(: $tbound:tt)?),*>)?) => {
impl $(<$($targ $(: $tbound)?),*>)? $crate::types::serialize::row::SerializeRow
impl $(<$($targ $(: $tbound)?),*>)? $crate::serialize::row::SerializeRow
for $t$(<$($targ),*>)?
where
Self: $crate::frame::value::ValueList,
{
fn serialize(
&self,
ctx: &$crate::types::serialize::row::RowSerializationContext<'_>,
writer: &mut $crate::types::serialize::writers::RowWriter,
) -> ::std::result::Result<(), $crate::types::serialize::SerializationError> {
$crate::types::serialize::row::serialize_legacy_row(self, ctx, writer)
ctx: &$crate::serialize::row::RowSerializationContext<'_>,
writer: &mut $crate::serialize::writers::RowWriter,
) -> ::std::result::Result<(), $crate::serialize::SerializationError> {
$crate::serialize::row::serialize_legacy_row(self, ctx, writer)
}

#[inline]
Expand Down Expand Up @@ -953,8 +959,8 @@ pub(crate) mod tests {
#[allow(deprecated)]
use crate::frame::value::{LegacySerializedValues, MaybeUnset, SerializedResult, ValueList};
#[allow(deprecated)]
use crate::types::serialize::row::ValueListAdapter;
use crate::types::serialize::{RowWriter, SerializationError};
use crate::serialize::row::ValueListAdapter;
use crate::serialize::{RowWriter, SerializationError};

use super::{
BuiltinSerializationError, BuiltinSerializationErrorKind, BuiltinTypeCheckError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,20 +954,20 @@ fn serialize_mapping<'t, 'b, K: SerializeValue + 't, V: SerializeValue + 't>(
#[macro_export]
macro_rules! impl_serialize_value_via_value {
($t:ident$(<$($targ:tt $(: $tbound:tt)?),*>)?) => {
impl $(<$($targ $(: $tbound)?),*>)? $crate::types::serialize::value::SerializeValue
impl $(<$($targ $(: $tbound)?),*>)? $crate::serialize::value::SerializeValue
for $t$(<$($targ),*>)?
where
Self: $crate::frame::value::Value,
{
fn serialize<'b>(
&self,
_typ: &$crate::frame::response::result::ColumnType,
writer: $crate::types::serialize::writers::CellWriter<'b>,
writer: $crate::serialize::writers::CellWriter<'b>,
) -> ::std::result::Result<
$crate::types::serialize::writers::WrittenCellProof<'b>,
$crate::types::serialize::SerializationError,
$crate::serialize::writers::WrittenCellProof<'b>,
$crate::serialize::SerializationError,
> {
$crate::types::serialize::value::serialize_legacy_value(self, writer)
$crate::serialize::value::serialize_legacy_value(self, writer)
}
}
};
Expand Down Expand Up @@ -1641,13 +1641,13 @@ pub(crate) mod tests {
#[allow(deprecated)]
use crate::frame::value::{Counter, MaybeUnset, Unset, Value, ValueTooBig};
#[allow(deprecated)]
use crate::types::serialize::value::{
use crate::serialize::value::{
BuiltinSerializationError, BuiltinSerializationErrorKind, BuiltinTypeCheckError,
BuiltinTypeCheckErrorKind, MapSerializationErrorKind, MapTypeCheckErrorKind,
SetOrListSerializationErrorKind, SetOrListTypeCheckErrorKind, TupleSerializationErrorKind,
TupleTypeCheckErrorKind, ValueAdapter,
};
use crate::types::serialize::{CellWriter, SerializationError};
use crate::serialize::{CellWriter, SerializationError};

use assert_matches::assert_matches;
use scylla_macros::SerializeValue;
Expand Down
File renamed without changes.
5 changes: 0 additions & 5 deletions scylla-cql/src/types/mod.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ mod derive_macros_integration {
mod value {
use bytes::Bytes;

use crate::deserialize::value::tests::{deserialize, udt_def_with_fields};
use crate::frame::response::result::ColumnType;
use crate::types::deserialize::value::tests::{deserialize, udt_def_with_fields};
use crate::types::serialize::value::tests::do_serialize;
use crate::serialize::value::tests::do_serialize;

#[test]
fn derive_serialize_and_deserialize_value_loose_ordering() {
Expand Down Expand Up @@ -153,10 +153,10 @@ mod derive_macros_integration {
mod row {
use bytes::Bytes;

use crate::deserialize::row::tests::deserialize;
use crate::deserialize::tests::spec;
use crate::frame::response::result::ColumnType;
use crate::types::deserialize::row::tests::deserialize;
use crate::types::deserialize::tests::spec;
use crate::types::serialize::row::tests::do_serialize;
use crate::serialize::row::tests::do_serialize;

#[test]
fn derive_serialize_and_deserialize_row_loose_ordering() {
Expand Down
5 changes: 2 additions & 3 deletions scylla-macros/src/deserialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ where
// - either:
// - the inner code would have to represent unnamed fields differently and handle the errors differently,
// - or we could use `.0, .1` or `0`, `1` as names for consecutive fields, making representation and error handling uniform.
let fields = crate::parser::parse_named_fields(input, trait_name)
.unwrap_or_else(|err| panic!("{}", err))
let fields = crate::parser::parse_named_fields(input, trait_name)?
.named
.iter()
.map(Field::from_field)
Expand Down Expand Up @@ -132,7 +131,7 @@ fn generate_default_constraints<Field: DeserializeCommonFieldAttrs>(
) -> impl Iterator<Item = syn::WherePredicate> + '_ {
fields.iter().filter(|f| f.needs_default()).map(|f| {
let t = f.deserialize_target();
parse_quote!(#t: std::default::Default)
parse_quote!(#t: ::std::default::Default)
})
}

Expand Down
Loading

0 comments on commit bb824b6

Please sign in to comment.