Skip to content

Commit

Permalink
feat: impl canonical (de)serialization for Arc<[T]>
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <[email protected]>
  • Loading branch information
ljedrz committed Dec 5, 2023
1 parent c845d63 commit e964144
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions utilities/src/serialize/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,45 @@ impl<T: CanonicalDeserialize + ToOwned + Sync + Send> CanonicalDeserialize for A
}
}

impl<T: CanonicalSerialize + ToOwned> CanonicalSerialize for Arc<[T]> {
#[inline]
fn serialize_with_mode<W: Write>(&self, mut writer: W, compress: Compress) -> Result<(), SerializationError> {
self.as_ref().serialize_with_mode(&mut writer, compress)
}

#[inline]
fn serialized_size(&self, compress: Compress) -> usize {
self.as_ref().serialized_size(compress)
}
}

impl<T: Valid + Sync + Send> Valid for Arc<[T]> {
#[inline]
fn check(&self) -> Result<(), SerializationError> {
T::batch_check(self.as_ref().iter())
}

#[inline]

fn batch_check<'a>(batch: impl Iterator<Item = &'a Self> + Send) -> Result<(), SerializationError>
where
Self: 'a,
{
T::batch_check(batch.map(|e| e.as_ref()).flatten())
}
}

impl<T: CanonicalDeserialize + ToOwned + Sync + Send> CanonicalDeserialize for Arc<[T]> {
#[inline]
fn deserialize_with_mode<R: Read>(
reader: R,
compress: Compress,
validate: Validate,
) -> Result<Self, SerializationError> {
Ok(Vec::<T>::deserialize_with_mode(reader, compress, validate)?.into())
}
}

impl<'a, T: CanonicalSerialize + ToOwned> CanonicalSerialize for Cow<'a, T> {
#[inline]
fn serialize_with_mode<W: Write>(&self, mut writer: W, compress: Compress) -> Result<(), SerializationError> {
Expand Down

0 comments on commit e964144

Please sign in to comment.