diff --git a/utils/zerovec/derive/examples/make_var.rs b/utils/zerovec/derive/examples/make_var.rs index 0c9a2a7f70d..47e1418cdb1 100644 --- a/utils/zerovec/derive/examples/make_var.rs +++ b/utils/zerovec/derive/examples/make_var.rs @@ -59,6 +59,20 @@ struct MultiFieldStruct<'a> { f: char, } +#[make_varule(MultiFieldConsecutiveStructULE)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, serde::Serialize, serde::Deserialize)] +#[zerovec::derive(Serialize, Deserialize, Debug)] +struct MultiFieldConsecutiveStruct<'a> { + #[serde(borrow)] + a: Cow<'a, str>, + #[serde(borrow)] + b: Cow<'a, str>, + #[serde(borrow)] + c: Cow<'a, str>, + #[serde(borrow)] + d: Cow<'a, str>, +} + #[make_varule(CustomVarFieldULE)] #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, serde::Serialize, serde::Deserialize)] #[zerovec::derive(Serialize, Deserialize, Debug)] @@ -139,6 +153,11 @@ fn main() { assert_eq!(stack, &MultiFieldStruct::zero_from(zero)) }); + assert_zerovec::( + TEST_MULTICONSECUTIVE, + |stack, zero| assert_eq!(stack, &MultiFieldConsecutiveStruct::zero_from(zero)), + ); + let vartuples = &[ VarTupleStruct(101, 'ø', TEST_STRINGS1.into()), VarTupleStruct(9499, '⸘', TEST_STRINGS2.into()), @@ -197,3 +216,11 @@ const TEST_MULTIFIELD: &[MultiFieldStruct<'static>] = &[ f: 'ə', }, ]; + +const TEST_MULTICONSECUTIVE: &[MultiFieldConsecutiveStruct<'static>] = + &[MultiFieldConsecutiveStruct { + a: Cow::Borrowed("one"), + b: Cow::Borrowed("2"), + c: Cow::Borrowed("three"), + d: Cow::Borrowed("four"), + }]; diff --git a/utils/zerovec/src/ule/multi.rs b/utils/zerovec/src/ule/multi.rs index 0ba0aea897d..3281b208882 100644 --- a/utils/zerovec/src/ule/multi.rs +++ b/utils/zerovec/src/ule/multi.rs @@ -44,7 +44,7 @@ impl MultiFieldsULE { lengths, output, ); debug_assert!( - >::validate_byte_slice(output).is_ok(), + >::validate_byte_slice(output).is_ok(), "Encoded slice must be valid VarZeroSlice" ); // Safe since write_serializable_bytes produces a valid VarZeroSlice buffer @@ -141,12 +141,14 @@ unsafe impl VarULE for MultiFieldsULE { /// This impl exists so that EncodeAsVarULE can work. #[inline] fn validate_byte_slice(slice: &[u8]) -> Result<(), ZeroVecError> { - >::validate_byte_slice(slice) + >::validate_byte_slice(slice) } #[inline] unsafe fn from_byte_slice_unchecked(bytes: &[u8]) -> &Self { // &Self is transparent over &VZS<..> - mem::transmute(>::from_byte_slice_unchecked(bytes)) + mem::transmute(>::from_byte_slice_unchecked( + bytes, + )) } }