Skip to content

Commit e2bedf6

Browse files
committed
Allow non-rust idents column names in SerializeRow derived struct
fixes cases where the "column name" is not a valid rust identifier; such as trying to pass in a dynamic TTL
1 parent 62f96b3 commit e2bedf6

File tree

2 files changed

+18
-1
lines changed
  • scylla-cql/src/types/serialize
  • scylla-macros/src/serialize

2 files changed

+18
-1
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,23 @@ pub(crate) mod tests {
15681568
assert_eq!(reference, row);
15691569
}
15701570

1571+
#[test]
1572+
fn test_row_serialization_with_not_rust_idents() {
1573+
#[derive(SerializeRow, Debug)]
1574+
#[scylla(crate = crate)]
1575+
struct RowWithTTL {
1576+
#[scylla(rename = "[ttl]")]
1577+
ttl: i32,
1578+
}
1579+
1580+
let spec = [col("[ttl]", ColumnType::Int)];
1581+
1582+
let reference = do_serialize((42i32,), &spec);
1583+
let row = do_serialize(RowWithTTL { ttl: 42 }, &spec);
1584+
1585+
assert_eq!(reference, row);
1586+
}
1587+
15711588
#[derive(SerializeRow, Debug)]
15721589
#[scylla(crate = crate)]
15731590
struct TestRowWithSkippedFields {

scylla-macros/src/serialize/row.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl Generator for ColumnSortingGenerator<'_> {
223223
statements.push(self.ctx.generate_mk_ser_err());
224224

225225
// Generate a "visited" flag for each field
226-
let visited_flag_names = rust_field_names
226+
let visited_flag_names = rust_field_idents
227227
.iter()
228228
.map(|s| syn::Ident::new(&format!("visited_flag_{}", s), Span::call_site()))
229229
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)