Skip to content

Commit 7cdf381

Browse files
committed
Add SerializeValue impl for Arc<T>
We already have one for Box, I see no reason to not have Arc as well.
1 parent e915b94 commit 7cdf381

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

scylla-cql/src/serialize/value.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,15 @@ impl<T: SerializeValue + ?Sized> SerializeValue for Box<T> {
409409
T::serialize(&**self, typ, writer).map_err(fix_rust_name_in_err::<Self>)
410410
}
411411
}
412+
impl<T: SerializeValue + ?Sized> SerializeValue for Arc<T> {
413+
fn serialize<'b>(
414+
&self,
415+
typ: &ColumnType,
416+
writer: CellWriter<'b>,
417+
) -> Result<WrittenCellProof<'b>, SerializationError> {
418+
T::serialize(&**self, typ, writer).map_err(fix_rust_name_in_err::<Self>)
419+
}
420+
}
412421
impl<V: SerializeValue, S: BuildHasher + Default> SerializeValue for HashSet<V, S> {
413422
fn serialize<'b>(
414423
&self,

scylla-cql/src/serialize/value_tests.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ fn test_box_errors() {
194194
));
195195
}
196196

197+
#[test]
198+
fn test_arc_errors() {
199+
verify_typeck_error_in_wrapper::<Arc<i32>>(Arc::new(123));
200+
verify_custom_error_in_wrapper::<Arc<SerializeWithCustomError>>(Arc::new(
201+
SerializeWithCustomError,
202+
));
203+
}
204+
197205
#[cfg(feature = "bigdecimal-04")]
198206
#[test]
199207
fn test_native_errors_bigdecimal_04() {
@@ -2225,6 +2233,15 @@ fn box_serialization() {
22252233
);
22262234
}
22272235

2236+
#[test]
2237+
fn arc_serialization() {
2238+
let x: Arc<i32> = Arc::new(123);
2239+
assert_eq!(
2240+
do_serialize(x, &ColumnType::Native(NativeType::Int)),
2241+
vec![0, 0, 0, 4, 0, 0, 0, 123]
2242+
);
2243+
}
2244+
22282245
#[test]
22292246
fn vec_set_serialization() {
22302247
let m = vec!["ala", "ma", "kota"];

0 commit comments

Comments
 (0)