Skip to content

Commit

Permalink
make the named lifetime of serialize more unique
Browse files Browse the repository at this point in the history
otherwise it can't compile if the impl block already had a 'b named lifetime
  • Loading branch information
nrxus committed Dec 24, 2024
1 parent 455abd0 commit 20f91e5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
54 changes: 54 additions & 0 deletions scylla-cql/src/types/serialize/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1790,4 +1790,58 @@ pub(crate) mod tests {

assert_eq!(reference, row);
}

#[test]
fn test_name_flatten_with_lifetimes() {
#[derive(SerializeRow)]
#[scylla(crate = crate, flavor = "enforce_order")]
struct Inner<'b> {
b: &'b bool,
}

#[derive(SerializeRow)]
#[scylla(crate = crate, flavor = "enforce_order")]
struct Outer<'a, 'b> {
#[scylla(flatten)]
inner: &'a Inner<'b>,
}

let b = true;
let inner = Inner { b: &b };

let value = Outer { inner: &inner };
let spec = [col("b", ColumnType::Boolean)];

let reference = do_serialize((&value.inner.b,), &spec);
let row = do_serialize(value, &spec);

assert_eq!(reference, row);
}

#[test]
fn test_ordered_flatten_with_lifetimes() {
#[derive(SerializeRow)]
#[scylla(crate = crate, flavor = "enforce_order")]
struct Inner<'b> {
b: &'b bool,
}

#[derive(SerializeRow)]
#[scylla(crate = crate, flavor = "enforce_order")]
struct Outer<'a, 'b> {
#[scylla(flatten)]
inner: &'a Inner<'b>,
}

let b = true;
let inner = Inner { b: &b };

let value = Outer { inner: &inner };
let spec = [col("b", ColumnType::Boolean)];

let reference = do_serialize((&value.inner.b,), &spec);
let row = do_serialize(value, &spec);

assert_eq!(reference, row);
}
}
8 changes: 4 additions & 4 deletions scylla-macros/src/serialize/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ impl Generator for ColumnSortingGenerator<'_> {
};

parse_quote! {
fn serialize<'b>(
fn serialize<'_scylla_ser_row_writer_buffer>(
&self,
ctx: &#crate_path::RowSerializationContext,
writer: &mut #crate_path::RowWriter<'b>,
writer: &mut #crate_path::RowWriter<'_scylla_ser_row_writer_buffer>,
) -> ::std::result::Result<(), #crate_path::SerializationError> {
#partial_struct
#partial_serialize
Expand Down Expand Up @@ -404,10 +404,10 @@ impl Generator for ColumnOrderedGenerator<'_> {
});

parse_quote! {
fn serialize<'b>(
fn serialize<'_scylla_ser_row_writer_buffer>(
&self,
ctx: &#crate_path::RowSerializationContext,
writer: &mut #crate_path::RowWriter<'b>,
writer: &mut #crate_path::RowWriter<'_scylla_ser_row_writer_buffer>,
) -> ::std::result::Result<(), #crate_path::SerializationError> {
#[allow(non_local_definitions)]
impl #impl_generics #crate_path::SerializeRowInOrder for #struct_name #ty_generics #where_clause {
Expand Down

0 comments on commit 20f91e5

Please sign in to comment.