diff --git a/scylla-cql/src/macros.rs b/scylla-cql/src/macros.rs index 62bb07f4fd..92b89f2c02 100644 --- a/scylla-cql/src/macros.rs +++ b/scylla-cql/src/macros.rs @@ -215,6 +215,10 @@ pub use scylla_macros::SerializeCql; /// /// Serializes the field to the column / bind marker with given name instead of /// its Rust name. +/// +/// `#[scylla(skip)]` +/// +/// Don't use the field during serialization. pub use scylla_macros::SerializeRow; // Reexports for derive(IntoUserType) diff --git a/scylla-cql/src/types/serialize/row.rs b/scylla-cql/src/types/serialize/row.rs index 451edb85ca..9cc214c03a 100644 --- a/scylla-cql/src/types/serialize/row.rs +++ b/scylla-cql/src/types/serialize/row.rs @@ -1519,4 +1519,43 @@ mod tests { assert_eq!(reference, row); } + + #[derive(SerializeRow, Debug)] + #[scylla(crate = crate)] + struct TestRowWithSkippedFields { + a: String, + b: i32, + #[scylla(skip)] + skipped: Vec, + c: Vec, + } + + #[test] + fn test_row_serialization_with_skipped_field() { + let spec = [ + col("a", ColumnType::Text), + col("b", ColumnType::Int), + col("c", ColumnType::List(Box::new(ColumnType::BigInt))), + ]; + + let reference = do_serialize( + TestRowWithColumnSorting { + a: "Ala ma kota".to_owned(), + b: 42, + c: vec![1, 2, 3], + }, + &spec, + ); + let row = do_serialize( + TestRowWithSkippedFields { + a: "Ala ma kota".to_owned(), + b: 42, + skipped: vec!["abcd".to_owned(), "efgh".to_owned()], + c: vec![1, 2, 3], + }, + &spec, + ); + + assert_eq!(reference, row); + } } diff --git a/scylla-macros/src/serialize/row.rs b/scylla-macros/src/serialize/row.rs index 122bed93dd..34bdce92c1 100644 --- a/scylla-macros/src/serialize/row.rs +++ b/scylla-macros/src/serialize/row.rs @@ -48,6 +48,9 @@ impl Field { #[darling(attributes(scylla))] struct FieldAttributes { rename: Option, + + #[darling(default)] + skip: bool, } struct Context { @@ -75,6 +78,9 @@ pub fn derive_serialize_row(tokens_input: TokenStream) -> Result>()?; let ctx = Context { attributes, fields }; ctx.validate(&input.ident)?;