diff --git a/scylla-cql/src/lib.rs b/scylla-cql/src/lib.rs index 7cecc575ab..fc40701901 100644 --- a/scylla-cql/src/lib.rs +++ b/scylla-cql/src/lib.rs @@ -95,6 +95,17 @@ pub mod _macro_internal { fn partial(&self) -> Self::Partial<'_>; } + impl SerializeRowByName for &T { + type Partial<'d> + = T::Partial<'d> + where + Self: 'd; + + fn partial(&self) -> Self::Partial<'_> { + ::partial(self) + } + } + /// How to serialize a row column-by-column /// /// For now this trait is an implementation detail of `#[derive(SerializeRow)]` when @@ -124,6 +135,16 @@ pub mod _macro_internal { ) -> Result<(), SerializationError>; } + impl SerializeRowInOrder for &T { + fn serialize_in_order( + &self, + columns: &mut self::ser::row::ByColumn<'_, '_>, + writer: &mut RowWriter<'_>, + ) -> Result<(), SerializationError> { + ::serialize_in_order(&self, columns, writer) + } + } + pub mod ser { pub mod row { use super::super::{ diff --git a/scylla-macros/src/serialize/row.rs b/scylla-macros/src/serialize/row.rs index 90415fd694..068156ad2f 100644 --- a/scylla-macros/src/serialize/row.rs +++ b/scylla-macros/src/serialize/row.rs @@ -205,11 +205,30 @@ impl Generator for ColumnSortingGenerator<'_> { struct_name.span(), ); let mut partial_generics = self.ctx.generics.clone(); - let partial_lt: syn::LifetimeParam = syn::parse_quote!('scylla_ser_partial); + let partial_lt: syn::Lifetime = syn::parse_quote!('scylla_ser_partial); + if !self.ctx.fields.is_empty() { + // all fields have to outlive the partial struct lifetime + partial_generics + .params + .iter_mut() + .filter_map(|p| match p { + syn::GenericParam::Lifetime(lt) => Some(lt), + _ => None, + }) + .for_each(|lt| { + lt.bounds.push(partial_lt.clone()); + }); + + // now add the partial struct lifetime partial_generics .params - .push(syn::GenericParam::Lifetime(partial_lt.clone())); + .push(syn::GenericParam::Lifetime(syn::LifetimeParam { + attrs: vec![], + lifetime: partial_lt.clone(), + colon_token: None, + bounds: syn::punctuated::Punctuated::new(), + })); } let (partial_impl_generics, partial_ty_generics, partial_where_clause) =