Skip to content

Commit

Permalink
Merge pull request scylladb#1105 from Daniel-Boll/feat/box-serialization
Browse files Browse the repository at this point in the history
feat(serialize): add `SerializeRow` impl for `Box<T: SerializeRow>`
  • Loading branch information
Lorak-mmk authored Oct 26, 2024
2 parents 6d14015 + 782cb1f commit 4649acb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scylla-cql/src/types/serialize/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ impl<T: SerializeValue> SerializeRow for Vec<T> {
impl_serialize_row_for_slice!();
}

impl<T: SerializeRow> SerializeRow for Box<T> {
#[inline]
fn serialize(
&self,
ctx: &RowSerializationContext<'_>,
writer: &mut RowWriter,
) -> Result<(), SerializationError> {
self.as_ref().serialize(ctx, writer)
}

#[inline]
fn is_empty(&self) -> bool {
self.as_ref().is_empty()
}
}

macro_rules! impl_serialize_row_for_map {
() => {
fn serialize(
Expand Down Expand Up @@ -1544,4 +1560,14 @@ mod tests {

assert_eq!(reference, row);
}

#[test]
fn test_row_serialization_with_boxed_tuple() {
let spec = [col("a", ColumnType::Int), col("b", ColumnType::Int)];

let reference = do_serialize((42i32, 42i32), &spec);
let row = do_serialize(Box::new((42i32, 42i32)), &spec);

assert_eq!(reference, row);
}
}

0 comments on commit 4649acb

Please sign in to comment.