diff --git a/components/casemap/src/provider/data.rs b/components/casemap/src/provider/data.rs index 533bdcde566..769ad118a45 100644 --- a/components/casemap/src/provider/data.rs +++ b/components/casemap/src/provider/data.rs @@ -271,7 +271,7 @@ impl CaseMapData { #[cfg(any(feature = "datagen", test))] pub(crate) fn try_from_icu_integer(int: u16) -> Result { let raw = int.to_unaligned(); - CaseMapDataULE::validate_byte_slice(raw.as_bytes())?; + CaseMapDataULE::validate_bytes(raw.as_bytes())?; let this = Self::from_unaligned(CaseMapDataULE(raw)); Ok(this) @@ -357,16 +357,16 @@ impl CaseMapDataULE { /// 1. The type *must not* include any uninitialized or padding bytes: repr(transparent) /// wrapper around ULE type /// 2. The type must have an alignment of 1 byte: repr(transparent) wrapper around ULE type -/// 3. The impl of [`ULE::validate_byte_slice()`] *must* return an error if the given byte slice +/// 3. The impl of [`ULE::validate_bytes()`] *must* return an error if the given byte slice /// would not represent a valid slice of this type: It does -/// 4. The impl of [`ULE::validate_byte_slice()`] *must* return an error if the given byte slice +/// 4. The impl of [`ULE::validate_bytes()`] *must* return an error if the given byte slice /// cannot be used in its entirety (if its length is not a multiple of `size_of::()`): /// it does, due to the RawBytesULE parse call /// 5. All other methods *must* be left with their default impl, or else implemented according to /// their respective safety guidelines: They have been /// 6. The equality invariant is satisfied unsafe impl ULE for CaseMapDataULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { let sixteens = RawBytesULE::<2>::parse_bytes(bytes)?; for sixteen in sixteens { diff --git a/components/datetime/src/fields/length.rs b/components/datetime/src/fields/length.rs index b42a9d8ef41..cf016138eaa 100644 --- a/components/datetime/src/fields/length.rs +++ b/components/datetime/src/fields/length.rs @@ -153,13 +153,13 @@ impl FieldLengthULE { // // 1. Must not include any uninitialized or padding bytes (true since transparent over a ULE). // 2. Must have an alignment of 1 byte (true since transparent over a ULE). -// 3. ULE::validate_byte_slice() checks that the given byte slice represents a valid slice. -// 4. ULE::validate_byte_slice() checks that the given byte slice has a valid length +// 3. ULE::validate_bytes() checks that the given byte slice represents a valid slice. +// 4. ULE::validate_bytes() checks that the given byte slice has a valid length // (true since transparent over a type of size 1). // 5. All other methods must be left with their default impl. // 6. Byte equality is semantic equality. unsafe impl ULE for FieldLengthULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { for byte in bytes { Self::validate_byte(*byte)?; } diff --git a/components/datetime/src/fields/mod.rs b/components/datetime/src/fields/mod.rs index cc7e6032ee3..133d0d7b1d8 100644 --- a/components/datetime/src/fields/mod.rs +++ b/components/datetime/src/fields/mod.rs @@ -178,7 +178,7 @@ mod test { bytes2.extend_from_slice(seq); } - assert!(FieldULE::validate_byte_slice(&bytes).is_ok()); + assert!(FieldULE::validate_bytes(&bytes).is_ok()); assert_eq!(bytes, bytes2); } } diff --git a/components/datetime/src/fields/symbols.rs b/components/datetime/src/fields/symbols.rs index 3a6bbb20184..217a04815fe 100644 --- a/components/datetime/src/fields/symbols.rs +++ b/components/datetime/src/fields/symbols.rs @@ -237,13 +237,13 @@ impl FieldSymbolULE { // // 1. Must not include any uninitialized or padding bytes (true since transparent over a ULE). // 2. Must have an alignment of 1 byte (true since transparent over a ULE). -// 3. ULE::validate_byte_slice() checks that the given byte slice represents a valid slice. -// 4. ULE::validate_byte_slice() checks that the given byte slice has a valid length +// 3. ULE::validate_bytes() checks that the given byte slice represents a valid slice. +// 4. ULE::validate_bytes() checks that the given byte slice has a valid length // (true since transparent over a type of size 1). // 5. All other methods must be left with their default impl. // 6. Byte equality is semantic equality. unsafe impl ULE for FieldSymbolULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { for byte in bytes { Self::validate_byte(*byte)?; } diff --git a/components/datetime/src/provider/pattern/item/ule.rs b/components/datetime/src/provider/pattern/item/ule.rs index 9fbc4413c90..e725b0ec2c0 100644 --- a/components/datetime/src/provider/pattern/item/ule.rs +++ b/components/datetime/src/provider/pattern/item/ule.rs @@ -88,12 +88,12 @@ impl PatternItemULE { // (achieved by `#[repr(transparent)]` on a ULE type) // 2. PatternItemULE is aligned to 1 byte. // (achieved by `#[repr(transparent)]` on a ULE type) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are extra bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. PatternItemULE byte equality is semantic equality. unsafe impl ULE for PatternItemULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { if bytes.len() % 3 != 0 { return Err(UleError::length::(bytes.len())); } @@ -245,12 +245,12 @@ impl GenericPatternItemULE { // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) // 2. GenericPatternItemULE is aligned to 1 byte. // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are extra bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. GenericPatternItemULE byte equality is semantic equality. unsafe impl ULE for GenericPatternItemULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { if bytes.len() % 3 != 0 { return Err(UleError::length::(bytes.len())); } @@ -384,7 +384,7 @@ mod test { bytes2.extend_from_slice(seq); } - assert!(PatternItemULE::validate_byte_slice(&bytes).is_ok()); + assert!(PatternItemULE::validate_bytes(&bytes).is_ok()); assert_eq!(bytes, bytes2); } } diff --git a/components/experimental/src/dimension/provider/compact_count_ule.rs b/components/experimental/src/dimension/provider/compact_count_ule.rs index 42cf4646369..1340d1fbf14 100644 --- a/components/experimental/src/dimension/provider/compact_count_ule.rs +++ b/components/experimental/src/dimension/provider/compact_count_ule.rs @@ -33,12 +33,12 @@ pub struct CompactCountULE(u8); // (achieved by `#[repr(transparent)]` on a ULE type) // 2. CompactCountULE is aligned to 1 byte. // (achieved by `#[repr(transparent)]` on a ULE type) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are extra bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. CompactCountULE byte equality is semantic equality. unsafe impl ULE for CompactCountULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { for byte in bytes { if byte & 0b0111_1000 != 0 { return Err(UleError::parse::()); diff --git a/components/experimental/src/dimension/provider/pattern_key.rs b/components/experimental/src/dimension/provider/pattern_key.rs index d9954841f75..7d2c0d24cf8 100644 --- a/components/experimental/src/dimension/provider/pattern_key.rs +++ b/components/experimental/src/dimension/provider/pattern_key.rs @@ -69,12 +69,12 @@ pub struct PatternKeyULE(u8); // (achieved by `#[repr(transparent)]` on a ULE type) // 2. PatternKeyULE is aligned to 1 byte. // (achieved by `#[repr(transparent)]` on a ULE type) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are extra bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. PatternKeyULE byte equality is semantic equality. unsafe impl ULE for PatternKeyULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { for &byte in bytes.iter() { // Ensure the first two bits (b7 & b6) are not 11. if (byte & 0b1100_0000) == 0b1100_0000 { @@ -176,12 +176,12 @@ fn test_pattern_key_ule() { let binary = PatternKey::Binary(0b0000_1111); let binary_ule = binary.to_unaligned(); - PatternKeyULE::validate_byte_slice(&[binary_ule.0]).unwrap(); + PatternKeyULE::validate_bytes(&[binary_ule.0]).unwrap(); assert_eq!(binary_ule.0, 0b0000_1111); let decimal = PatternKey::Decimal(0b0000_1111); let decimal_ule = decimal.to_unaligned(); - PatternKeyULE::validate_byte_slice(&[decimal_ule.0]).unwrap(); + PatternKeyULE::validate_bytes(&[decimal_ule.0]).unwrap(); assert_eq!(decimal_ule.0, 0b0100_1111); let power2 = PatternKey::Power { @@ -189,7 +189,7 @@ fn test_pattern_key_ule() { count: CompoundCount::Two, }; let power2_ule = power2.to_unaligned(); - PatternKeyULE::validate_byte_slice(&[power2_ule.0]).unwrap(); + PatternKeyULE::validate_bytes(&[power2_ule.0]).unwrap(); assert_eq!(power2_ule.0, 0b1010_0010); let power3 = PatternKey::Power { @@ -197,7 +197,7 @@ fn test_pattern_key_ule() { count: CompoundCount::Two, }; let power3_ule = power3.to_unaligned(); - PatternKeyULE::validate_byte_slice(&[power3_ule.0]).unwrap(); + PatternKeyULE::validate_bytes(&[power3_ule.0]).unwrap(); assert_eq!(power3_ule.0, 0b1011_0010); let binary = PatternKey::from_unaligned(binary_ule); @@ -234,13 +234,13 @@ fn test_pattern_key_ule() { // Test invalid bytes let unvalidated_bytes = [0b1100_0000]; assert_eq!( - PatternKeyULE::validate_byte_slice(&unvalidated_bytes), + PatternKeyULE::validate_bytes(&unvalidated_bytes), Err(UleError::parse::()) ); let unvalidated_bytes = [0b1000_0000]; assert_eq!( - PatternKeyULE::validate_byte_slice(&unvalidated_bytes), + PatternKeyULE::validate_bytes(&unvalidated_bytes), Err(UleError::parse::()) ); } diff --git a/components/experimental/src/dimension/provider/ule.rs b/components/experimental/src/dimension/provider/ule.rs index 177f03ec74f..a882e97db82 100644 --- a/components/experimental/src/dimension/provider/ule.rs +++ b/components/experimental/src/dimension/provider/ule.rs @@ -39,12 +39,12 @@ pub struct CurrencyPatternConfigULE([u8; 3]); // (achieved by `#[repr(transparent)]` on a ULE type) // 2. CurrencyPatternConfigULE is aligned to 1 byte. // (achieved by `#[repr(transparent)]` on a ULE type) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are extra bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. CurrencyPatternConfigULE byte equality is semantic equality. unsafe impl ULE for CurrencyPatternConfigULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { if bytes.len() % 3 != 0 { return Err(UleError::length::(bytes.len())); } diff --git a/components/locale_core/src/helpers.rs b/components/locale_core/src/helpers.rs index ae4589afd79..67cc5f6797e 100644 --- a/components/locale_core/src/helpers.rs +++ b/components/locale_core/src/helpers.rs @@ -278,13 +278,13 @@ macro_rules! impl_tinystr_subtag { // // 1. Must not include any uninitialized or padding bytes (true since transparent over a ULE). // 2. Must have an alignment of 1 byte (true since transparent over a ULE). - // 3. ULE::validate_byte_slice() checks that the given byte slice represents a valid slice. - // 4. ULE::validate_byte_slice() checks that the given byte slice has a valid length. + // 3. ULE::validate_bytes() checks that the given byte slice represents a valid slice. + // 4. ULE::validate_bytes() checks that the given byte slice has a valid length. // 5. All other methods must be left with their default impl. // 6. Byte equality is semantic equality. #[cfg(feature = "zerovec")] unsafe impl zerovec::ule::ULE for $name { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { let it = bytes.chunks_exact(core::mem::size_of::()); if !it.remainder().is_empty() { return Err(zerovec::ule::UleError::length::(bytes.len())); diff --git a/components/pattern/src/implementations.rs b/components/pattern/src/implementations.rs index 84d2a2b8a17..fe6eebb65e6 100644 --- a/components/pattern/src/implementations.rs +++ b/components/pattern/src/implementations.rs @@ -29,18 +29,18 @@ where /// /// 1. `Pattern` does not include any uninitialized or padding bytes. /// 2. `Pattern` is aligned to 1 byte. -/// 3. The implementation of `validate_byte_slice()` returns an error +/// 3. The implementation of `validate_bytes()` returns an error /// if any byte is not valid. -/// 4. The implementation of `validate_byte_slice()` returns an error +/// 4. The implementation of `validate_bytes()` returns an error /// if the slice cannot be used to build a `Pattern` in its entirety. /// 5. The implementation of `from_bytes_unchecked()` returns a reference to the same data. -/// 6. `parse_bytes()` is equivalent to `validate_byte_slice()` followed by `from_bytes_unchecked()`. +/// 6. `parse_bytes()` is equivalent to `validate_bytes()` followed by `from_bytes_unchecked()`. /// 7. `Pattern` byte equality is semantic equality. unsafe impl VarULE for Pattern where B: PatternBackend, { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { let store = S::parse_bytes(bytes)?; B::validate_store(store).map_err(|_| UleError::parse::()) } diff --git a/components/plurals/src/provider.rs b/components/plurals/src/provider.rs index 977522b9153..b551e78ca66 100644 --- a/components/plurals/src/provider.rs +++ b/components/plurals/src/provider.rs @@ -399,7 +399,7 @@ unsafe impl VarULE for PluralElementsPackedULE where V: VarULE + ?Sized, { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { let unpacked_bytes = Self::unpack_bytes(bytes).ok_or_else(|| UleError::length::(bytes.len()))?; // The high bit of lead_byte was read in unpack_bytes. @@ -409,9 +409,9 @@ where return Err(UleError::parse::()); } // Now validate the two variable-length slices. - V::validate_byte_slice(unpacked_bytes.v_bytes)?; + V::validate_bytes(unpacked_bytes.v_bytes)?; if let Some(specials_bytes) = unpacked_bytes.specials_bytes { - PluralElementsTupleSliceVarULE::::validate_byte_slice(specials_bytes)?; + PluralElementsTupleSliceVarULE::::validate_bytes(specials_bytes)?; } Ok(()) } @@ -430,7 +430,7 @@ where /// /// # Safety /// - /// The bytes must be valid according to [`PluralElementsPackedULE::validate_byte_slice`]. + /// The bytes must be valid according to [`PluralElementsPackedULE::validate_bytes`]. pub const unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self { // Safety: the bytes are valid by trait invariant, and we are transparent over bytes core::mem::transmute(bytes) @@ -654,12 +654,12 @@ impl From for PluralCategoryAndMetadataPackedULE { // // 1. The type is a single byte, not padding. // 2. The type is a single byte, so it has align(1). -// 3. `validate_byte_slice` checks the validity of every byte. -// 4. `validate_byte_slice` checks the validity of every byte. +// 3. `validate_bytes` checks the validity of every byte. +// 4. `validate_bytes` checks the validity of every byte. // 5. All other methods are be left with their default impl. // 6. The represented enums implement Eq by byte equality. unsafe impl ULE for PluralCategoryAndMetadataPackedULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { bytes .iter() .all(|byte| { diff --git a/components/plurals/src/rules/runtime/ast.rs b/components/plurals/src/rules/runtime/ast.rs index 66c72671c40..2666f50a432 100644 --- a/components/plurals/src/rules/runtime/ast.rs +++ b/components/plurals/src/rules/runtime/ast.rs @@ -288,13 +288,13 @@ pub(crate) struct AndOrPolarityOperandULE(u8); // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) /// 2. AndOrPolarityOperandULE is aligned to 1 byte // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are extra bytes +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are extra bytes // (impossible since it is of size 1 byte) // 5 The other ULE methods use the default impl. // 6. AndOrPolarityOperandULE byte equality is semantic equality. unsafe impl ULE for AndOrPolarityOperandULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { for byte in bytes { Operand::new_from_u8(byte & 0b0011_1111).ok_or_else(UleError::parse::)?; } diff --git a/utils/potential_utf/src/ustr.rs b/utils/potential_utf/src/ustr.rs index 87eb1157d4b..970de6afdf4 100644 --- a/utils/potential_utf/src/ustr.rs +++ b/utils/potential_utf/src/ustr.rs @@ -143,8 +143,8 @@ impl<'a> zerovec::maps::ZeroMapKV<'a> for PotentialUtf8 { // Safety (based on the safety checklist on the VarULE trait): // 1. PotentialUtf8 does not include any uninitialized or padding bytes (transparent over a ULE) // 2. PotentialUtf8 is aligned to 1 byte (transparent over a ULE) -// 3. The impl of `validate_byte_slice()` returns an error if any byte is not valid (impossible) -// 4. The impl of `validate_byte_slice()` returns an error if the slice cannot be used in its entirety (impossible) +// 3. The impl of `validate_bytes()` returns an error if any byte is not valid (impossible) +// 4. The impl of `validate_bytes()` returns an error if the slice cannot be used in its entirety (impossible) // 5. The impl of `from_bytes_unchecked()` returns a reference to the same data (returns the argument directly) // 6. All other methods are defaulted // 7. `[T]` byte equality is semantic equality (transparent over a ULE) @@ -152,7 +152,7 @@ impl<'a> zerovec::maps::ZeroMapKV<'a> for PotentialUtf8 { #[cfg(feature = "zerovec")] unsafe impl zerovec::ule::VarULE for PotentialUtf8 { #[inline] - fn validate_byte_slice(_: &[u8]) -> Result<(), zerovec::ule::UleError> { + fn validate_bytes(_: &[u8]) -> Result<(), zerovec::ule::UleError> { Ok(()) } #[inline] diff --git a/utils/tinystr/src/ule.rs b/utils/tinystr/src/ule.rs index 247028be893..c6b8782f746 100644 --- a/utils/tinystr/src/ule.rs +++ b/utils/tinystr/src/ule.rs @@ -12,13 +12,13 @@ use zerovec::{ZeroSlice, ZeroVec}; // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) // 2. TinyAsciiStr is aligned to 1 byte. // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are extra bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. TinyAsciiStr byte equality is semantic equality unsafe impl ULE for TinyAsciiStr { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { if bytes.len() % N != 0 { return Err(UleError::length::(bytes.len())); } @@ -62,13 +62,13 @@ impl<'a, const N: usize> ZeroMapKV<'a> for TinyAsciiStr { // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) // 2. UnvalidatedTinyAsciiStr is aligned to 1 byte. // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are extra bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. UnvalidatedTinyAsciiStr byte equality is semantic equality unsafe impl ULE for UnvalidatedTinyAsciiStr { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { if bytes.len() % N != 0 { return Err(UleError::length::(bytes.len())); } diff --git a/utils/zerotrie/src/zerotrie.rs b/utils/zerotrie/src/zerotrie.rs index a5e6107b1e2..13fbeb7f289 100644 --- a/utils/zerotrie/src/zerotrie.rs +++ b/utils/zerotrie/src/zerotrie.rs @@ -605,8 +605,8 @@ macro_rules! impl_zerotrie_subtype { Store: zerovec::ule::VarULE, { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { - Store::validate_byte_slice(bytes) + fn validate_bytes(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { + Store::validate_bytes(bytes) } #[inline] unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self { diff --git a/utils/zerovec/derive/src/make_ule.rs b/utils/zerovec/derive/src/make_ule.rs index 3df0c6f7878..4dd3cb0b309 100644 --- a/utils/zerovec/derive/src/make_ule.rs +++ b/utils/zerovec/derive/src/make_ule.rs @@ -191,9 +191,9 @@ fn make_ule_enum_impl( // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant // 2. ULE type is aligned to 1 byte. // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) - // 3. The impl of validate_byte_slice() returns an error if any byte is not valid. + // 3. The impl of validate_bytes() returns an error if any byte is not valid. // (Guarantees that the byte is in range of the corresponding enum.) - // 4. The impl of validate_byte_slice() returns an error if there are extra bytes. + // 4. The impl of validate_bytes() returns an error if there are extra bytes. // (This does not happen since we are backed by 1 byte.) // 5. The other ULE methods use the default impl. // 6. ULE type byte equality is semantic equality @@ -206,7 +206,7 @@ fn make_ule_enum_impl( unsafe impl zerovec::ule::ULE for #ule_name { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { for byte in bytes { if *byte < #min || *byte > #max { return Err(zerovec::ule::UleError::parse::()) diff --git a/utils/zerovec/derive/src/ule.rs b/utils/zerovec/derive/src/ule.rs index 4d2b945129c..9279172a18e 100644 --- a/utils/zerovec/derive/src/ule.rs +++ b/utils/zerovec/derive/src/ule.rs @@ -51,14 +51,14 @@ pub fn derive_impl(input: &DeriveInput) -> TokenStream2 { // (achieved by enforcing #[repr(transparent)] or #[repr(C, packed)] on a struct of only ULE types) // 2. #name is aligned to 1 byte. // (achieved by enforcing #[repr(transparent)] or #[repr(C, packed)] on a struct of only ULE types) - // 3. The impl of validate_byte_slice() returns an error if any byte is not valid. - // 4. The impl of validate_byte_slice() returns an error if there are extra bytes. + // 3. The impl of validate_bytes() returns an error if any byte is not valid. + // 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. [This impl does not enforce the non-safety equality constraint, it is up to the user to do so, ideally via a custom derive] quote! { unsafe impl zerovec::ule::ULE for #name { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { const SIZE: usize = ::core::mem::size_of::<#name>(); #[allow(clippy::modulo_one)] if bytes.len() % SIZE != 0 { @@ -87,7 +87,7 @@ pub(crate) fn generate_ule_validators( let ty = &field.field.ty; quote! { #[allow(clippy::indexing_slicing)] // generate_per_field_offsets produces valid indices - <#ty as zerovec::ule::ULE>::validate_byte_slice(&bytes[#prev_offset_ident .. #prev_offset_ident + #size_ident])?; + <#ty as zerovec::ule::ULE>::validate_bytes(&bytes[#prev_offset_ident .. #prev_offset_ident + #size_ident])?; } }) } diff --git a/utils/zerovec/derive/src/varule.rs b/utils/zerovec/derive/src/varule.rs index e49d0284583..e923d090e8d 100644 --- a/utils/zerovec/derive/src/varule.rs +++ b/utils/zerovec/derive/src/varule.rs @@ -83,7 +83,7 @@ pub fn derive_impl( let last_field_validator = if let Some(custom_varule_validator) = custom_varule_validator { custom_varule_validator } else { - quote!(<#unsized_field as zerovec::ule::VarULE>::validate_byte_slice(last_field_bytes)?;) + quote!(<#unsized_field as zerovec::ule::VarULE>::validate_bytes(last_field_bytes)?;) }; // Safety (based on the safety checklist on the ULE trait): @@ -91,8 +91,8 @@ pub fn derive_impl( // (achieved by enforcing #[repr(transparent)] or #[repr(C, packed)] on a struct of only ULE types) // 2. #name is aligned to 1 byte. // (achieved by enforcing #[repr(transparent)] or #[repr(C, packed)] on a struct of only ULE types) - // 3. The impl of `validate_byte_slice()` returns an error if any byte is not valid. - // 4. The impl of `validate_byte_slice()` returns an error if the slice cannot be used in its entirety + // 3. The impl of `validate_bytes()` returns an error if any byte is not valid. + // 4. The impl of `validate_bytes()` returns an error if the slice cannot be used in its entirety // 5. The impl of `from_bytes_unchecked()` returns a reference to the same data. // 6. The other VarULE methods use the default impl // 7. [This impl does not enforce the non-safety equality constraint, it is up to the user to do so, ideally via a custom derive] @@ -101,7 +101,7 @@ pub fn derive_impl( const #ule_size: usize = 0 #(+ #sizes)*; unsafe impl zerovec::ule::VarULE for #name { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), zerovec::ule::UleError> { if bytes.len() < #ule_size { return Err(zerovec::ule::UleError::parse::()); diff --git a/utils/zerovec/design_doc.md b/utils/zerovec/design_doc.md index c95dfa8031a..3d0ba9f2cc5 100644 --- a/utils/zerovec/design_doc.md +++ b/utils/zerovec/design_doc.md @@ -174,7 +174,7 @@ where Self: Sized + Copy + 'static, { // Required - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError>; + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>; // Some automatically provided methods elided } @@ -214,7 +214,7 @@ Unsized types use [`VarULE`]. Unlike sized types, there is no `AsVarULE` type fo ```rust pub unsafe trait VarULE: 'static { - fn validate_byte_slice(_bytes: &[u8]) -> Result<(), UleError>; + fn validate_bytes(_bytes: &[u8]) -> Result<(), UleError>; unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self; // Some automatically provided methods elided @@ -317,7 +317,7 @@ These can only be applied to structs where all fields are ULE types (for `#[deri - Apply `#[repr(C, packed)]` to the type (or perhaps `#[repr(C)]` if we can determine that that will always work) - Generate the appropriate `ZeroMapKV` impl (an opt-out can be provided) - - Generate a `ULE` or `VarULE` implementation that applies offsetted `validate_byte_slice()` for each field to implement the final `validate_byte_slice()` + - Generate a `ULE` or `VarULE` implementation that applies offsetted `validate_bytes()` for each field to implement the final `validate_bytes()` - Generate `Copy`/`Clone` impls as necessary (`#[derive()]` does not work with packed types) Ideally an option can be used to request further stdlib derives on the ULE type diff --git a/utils/zerovec/src/cow.rs b/utils/zerovec/src/cow.rs index ccfce92c19e..7b90f2c4681 100644 --- a/utils/zerovec/src/cow.rs +++ b/utils/zerovec/src/cow.rs @@ -98,7 +98,7 @@ impl<'a, V: VarULE + ?Sized> VarZeroCow<'a, V> { /// Construct from an owned slice. Errors if the slice doesn't represent a valid `V` pub fn parse_owned_bytes(bytes: Box<[u8]>) -> Result { - V::validate_byte_slice(&bytes)?; + V::validate_bytes(&bytes)?; let bytes = ManuallyDrop::new(bytes); let buf: NonNull<[u8]> = (&**bytes).into(); Ok(Self { @@ -116,7 +116,7 @@ impl<'a, V: VarULE + ?Sized> VarZeroCow<'a, V> { /// # Safety /// /// `bytes` must be a valid `V`, i.e. it must successfully pass through - /// `V::parse_bytes()` or `V::validate_byte_slice()`. + /// `V::parse_bytes()` or `V::validate_bytes()`. pub const unsafe fn from_bytes_unchecked(bytes: &'a [u8]) -> Self { unsafe { // Safety: bytes is an &T which is always non-null diff --git a/utils/zerovec/src/ule/chars.rs b/utils/zerovec/src/ule/chars.rs index 380e5850048..a16a8b03da3 100644 --- a/utils/zerovec/src/ule/chars.rs +++ b/utils/zerovec/src/ule/chars.rs @@ -71,13 +71,13 @@ impl CharULE { // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) // 2. CharULE is aligned to 1 byte. // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are extra bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. CharULE byte equality is semantic equality unsafe impl ULE for CharULE { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { if bytes.len() % 3 != 0 { return Err(UleError::length::(bytes.len())); } diff --git a/utils/zerovec/src/ule/custom.rs b/utils/zerovec/src/ule/custom.rs index 84b3141dbdf..fd283ef75d4 100644 --- a/utils/zerovec/src/ule/custom.rs +++ b/utils/zerovec/src/ule/custom.rs @@ -61,16 +61,16 @@ //! // a struct with only ULE fields) //! // 2. FooULE is aligned to 1 byte. (achieved by `#[repr(C, packed)]` on //! // a struct with only ULE fields) -//! // 3. The impl of `validate_byte_slice()` returns an error if any byte is not valid. -//! // 4. The impl of `validate_byte_slice()` returns an error if the slice cannot be used in its entirety +//! // 3. The impl of `validate_bytes()` returns an error if any byte is not valid. +//! // 4. The impl of `validate_bytes()` returns an error if the slice cannot be used in its entirety //! // 5. The impl of `from_bytes_unchecked()` returns a reference to the same data. //! // 6. The other VarULE methods use the default impl. //! // 7. FooULE byte equality is semantic equality //! unsafe impl VarULE for FooULE { -//! fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { +//! fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { //! // validate each field -//! ::ULE::validate_byte_slice(&bytes[0..3]).map_err(|_| UleError::parse::())?; -//! ::ULE::validate_byte_slice(&bytes[3..7]).map_err(|_| UleError::parse::())?; +//! ::ULE::validate_bytes(&bytes[0..3]).map_err(|_| UleError::parse::())?; +//! ::ULE::validate_bytes(&bytes[3..7]).map_err(|_| UleError::parse::())?; //! let _ = ZeroVec::::parse_bytes(&bytes[7..]).map_err(|_| UleError::parse::())?; //! Ok(()) //! } diff --git a/utils/zerovec/src/ule/encode.rs b/utils/zerovec/src/ule/encode.rs index 7049f4d15e4..82402580b71 100644 --- a/utils/zerovec/src/ule/encode.rs +++ b/utils/zerovec/src/ule/encode.rs @@ -39,7 +39,7 @@ use core::mem; /// The safety invariants of [`Self::encode_var_ule_as_slices()`] are: /// - It must call `cb` (only once) /// - The slices passed to `cb`, if concatenated, should be a valid instance of the `T` [`VarULE`] type -/// (i.e. if fed to [`VarULE::validate_byte_slice()`] they must produce a successful result) +/// (i.e. if fed to [`VarULE::validate_bytes()`] they must produce a successful result) /// - It must return the return value of `cb` to the caller /// /// One or more of [`Self::encode_var_ule_len()`] and [`Self::encode_var_ule_write()`] may be provided. diff --git a/utils/zerovec/src/ule/mod.rs b/utils/zerovec/src/ule/mod.rs index 94c8dc0d597..5c8ccb7361a 100644 --- a/utils/zerovec/src/ule/mod.rs +++ b/utils/zerovec/src/ule/mod.rs @@ -53,9 +53,9 @@ use core::{any, fmt, mem, slice}; /// /// 1. The type *must not* include any uninitialized or padding bytes. /// 2. The type must have an alignment of 1 byte. -/// 3. The impl of [`ULE::validate_byte_slice()`] *must* return an error if the given byte slice +/// 3. The impl of [`ULE::validate_bytes()`] *must* return an error if the given byte slice /// would not represent a valid slice of this type. -/// 4. The impl of [`ULE::validate_byte_slice()`] *must* return an error if the given byte slice +/// 4. The impl of [`ULE::validate_bytes()`] *must* return an error if the given byte slice /// cannot be used in its entirety (if its length is not a multiple of `size_of::()`). /// 5. All other methods *must* be left with their default impl, or else implemented according to /// their respective safety guidelines. @@ -70,7 +70,7 @@ use core::{any, fmt, mem, slice}; /// equivalent to byte equality on [`Self::as_bytes()`]. /// /// It may be necessary to introduce a "canonical form" of the ULE if logical equality does not -/// equal byte equality. In such a case, [`Self::validate_byte_slice()`] should return an error +/// equal byte equality. In such a case, [`Self::validate_bytes()`] should return an error /// for any values that are not in canonical form. For example, the decimal strings "1.23e4" and /// "12.3e3" are logically equal, but not byte-for-byte equal, so we could define a canonical form /// where only a single digit is allowed before `.`. @@ -87,20 +87,20 @@ where /// If `Self` is not well-defined for all possible bit values, the bytes should be validated. /// If the bytes can be transmuted, *in their entirety*, to a valid slice of `Self`, then `Ok` /// should be returned; otherwise, `Err` should be returned. - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError>; + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError>; /// Parses a byte slice, `&[u8]`, and return it as `&[Self]` with the same lifetime. /// /// If `Self` is not well-defined for all possible bit values, the bytes should be validated, - /// and an error should be returned in the same cases as [`Self::validate_byte_slice()`]. + /// and an error should be returned in the same cases as [`Self::validate_bytes()`]. /// - /// The default implementation executes [`Self::validate_byte_slice()`] followed by + /// The default implementation executes [`Self::validate_bytes()`] followed by /// [`Self::from_bytes_unchecked`]. /// /// Note: The following equality should hold: `bytes.len() % size_of::() == 0`. This /// means that the returned slice can span the entire byte slice. fn parse_bytes(bytes: &[u8]) -> Result<&[Self], UleError> { - Self::validate_byte_slice(bytes)?; + Self::validate_bytes(bytes)?; debug_assert_eq!(bytes.len() % mem::size_of::(), 0); Ok(unsafe { Self::from_bytes_unchecked(bytes) }) } @@ -116,7 +116,7 @@ where /// ## Callers /// /// Callers of this method must take care to ensure that `bytes` was previously passed through - /// [`Self::validate_byte_slice()`] with success (and was not changed since then). + /// [`Self::validate_bytes()`] with success (and was not changed since then). /// /// ## Implementors /// @@ -263,9 +263,9 @@ where /// /// 1. The type *must not* include any uninitialized or padding bytes. /// 2. The type must have an alignment of 1 byte. -/// 3. The impl of [`VarULE::validate_byte_slice()`] *must* return an error if the given byte slice +/// 3. The impl of [`VarULE::validate_bytes()`] *must* return an error if the given byte slice /// would not represent a valid slice of this type. -/// 4. The impl of [`VarULE::validate_byte_slice()`] *must* return an error if the given byte slice +/// 4. The impl of [`VarULE::validate_bytes()`] *must* return an error if the given byte slice /// cannot be used in its entirety. /// 5. The impl of [`VarULE::from_bytes_unchecked()`] must produce a reference to the same /// underlying data assuming that the given bytes previously passed validation. @@ -282,7 +282,7 @@ where /// equivalent to byte equality on [`Self::as_bytes()`]. /// /// It may be necessary to introduce a "canonical form" of the ULE if logical equality does not -/// equal byte equality. In such a case, [`Self::validate_byte_slice()`] should return an error +/// equal byte equality. In such a case, [`Self::validate_bytes()`] should return an error /// for any values that are not in canonical form. For example, the decimal strings "1.23e4" and /// "12.3e3" are logically equal, but not byte-for-byte equal, so we could define a canonical form /// where only a single digit is allowed before `.`. @@ -301,21 +301,21 @@ pub unsafe trait VarULE: 'static { /// If `Self` is not well-defined for all possible bit values, the bytes should be validated. /// If the bytes can be transmuted, *in their entirety*, to a valid `&Self`, then `Ok` should /// be returned; otherwise, `Self::Error` should be returned. - fn validate_byte_slice(_bytes: &[u8]) -> Result<(), UleError>; + fn validate_bytes(_bytes: &[u8]) -> Result<(), UleError>; /// Parses a byte slice, `&[u8]`, and return it as `&Self` with the same lifetime. /// /// If `Self` is not well-defined for all possible bit values, the bytes should be validated, - /// and an error should be returned in the same cases as [`Self::validate_byte_slice()`]. + /// and an error should be returned in the same cases as [`Self::validate_bytes()`]. /// - /// The default implementation executes [`Self::validate_byte_slice()`] followed by + /// The default implementation executes [`Self::validate_bytes()`] followed by /// [`Self::from_bytes_unchecked`]. /// /// Note: The following equality should hold: `size_of_val(result) == size_of_val(bytes)`, /// where `result` is the successful return value of the method. This means that the return /// value spans the entire byte slice. fn parse_bytes(bytes: &[u8]) -> Result<&Self, UleError> { - Self::validate_byte_slice(bytes)?; + Self::validate_bytes(bytes)?; let result = unsafe { Self::from_bytes_unchecked(bytes) }; debug_assert_eq!(mem::size_of_val(result), mem::size_of_val(bytes)); Ok(result) @@ -330,7 +330,7 @@ pub unsafe trait VarULE: 'static { /// ## Callers /// /// Callers of this method must take care to ensure that `bytes` was previously passed through - /// [`Self::validate_byte_slice()`] with success (and was not changed since then). + /// [`Self::validate_bytes()`] with success (and was not changed since then). /// /// ## Implementors /// diff --git a/utils/zerovec/src/ule/multi.rs b/utils/zerovec/src/ule/multi.rs index b642cd5b7a7..687db63eae1 100644 --- a/utils/zerovec/src/ule/multi.rs +++ b/utils/zerovec/src/ule/multi.rs @@ -75,7 +75,7 @@ impl MultiFieldsULE { /// - `index` must be in range #[inline] pub unsafe fn validate_field(&self, index: usize) -> Result<(), UleError> { - T::validate_byte_slice(self.0.get_unchecked(LEN as u32, index)) + T::validate_bytes(self.0.get_unchecked(LEN as u32, index)) } /// Get field at `index` as a value of type T @@ -136,8 +136,8 @@ unsafe impl EncodeAsVarULE<[u8]> for BlankSliceEncoder { // Safety (based on the safety checklist on the VarULE trait): // 1. MultiFieldsULE does not include any uninitialized or padding bytes (achieved by being transparent over a VarULE type) // 2. MultiFieldsULE is aligned to 1 byte (achieved by being transparent over a VarULE type) -// 3. The impl of `validate_byte_slice()` returns an error if any byte is not valid. -// 4. The impl of `validate_byte_slice()` returns an error if the slice cannot be used in its entirety +// 3. The impl of `validate_bytes()` returns an error if any byte is not valid. +// 4. The impl of `validate_bytes()` returns an error if the slice cannot be used in its entirety // 5. The impl of `from_bytes_unchecked()` returns a reference to the same data. // 6. All other methods are defaulted // 7. `MultiFieldsULE` byte equality is semantic equality (achieved by being transparent over a VarULE type) @@ -147,7 +147,7 @@ unsafe impl VarULE for MultiFieldsUL /// /// This impl exists so that EncodeAsVarULE can work. #[inline] - fn validate_byte_slice(slice: &[u8]) -> Result<(), UleError> { + fn validate_bytes(slice: &[u8]) -> Result<(), UleError> { >::parse_bytes(LEN as u32, slice).map(|_| ()) } diff --git a/utils/zerovec/src/ule/niche.rs b/utils/zerovec/src/ule/niche.rs index 0407af17290..c2cb5ba1ec5 100644 --- a/utils/zerovec/src/ule/niche.rs +++ b/utils/zerovec/src/ule/niche.rs @@ -122,13 +122,13 @@ impl + ULE + Eq, const N: usize> Eq for NichedOptionULE { /// In both cases the data is initialized. /// 2. NichedOptionULE is aligned to 1 byte due to `#[repr(C, packed)]` on a struct containing only /// ULE fields. -/// 3. validate_byte_slice impl returns an error if invalid bytes are encountered. -/// 4. validate_byte_slice impl returns an error there are extra bytes. +/// 3. validate_bytes impl returns an error if invalid bytes are encountered. +/// 4. validate_bytes impl returns an error there are extra bytes. /// 5. The other ULE methods are left to their default impl. /// 6. NichedOptionULE equality is based on ULE equality of the subfield, assuming that NicheBytes /// has been implemented correctly (this is a correctness but not a safety guarantee). unsafe impl + ULE, const N: usize> ULE for NichedOptionULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), crate::ule::UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), crate::ule::UleError> { let size = size_of::(); // The implemention is only correct if NICHE_BIT_PATTERN has same number of bytes as the // type. @@ -144,7 +144,7 @@ unsafe impl + ULE, const N: usize> ULE for NichedOptionULE>::NICHE_BIT_PATTERN { Ok(()) } else { - U::validate_byte_slice(chunk) + U::validate_bytes(chunk) } }) } diff --git a/utils/zerovec/src/ule/option.rs b/utils/zerovec/src/ule/option.rs index 79b86cc5676..42fcc69a4c9 100644 --- a/utils/zerovec/src/ule/option.rs +++ b/utils/zerovec/src/ule/option.rs @@ -67,13 +67,13 @@ impl core::fmt::Debug for OptionULE { /// zeroed or valid-T byte sequences to fill it) // 2. OptionULE is aligned to 1 byte. // (achieved by `#[repr(C, packed)]` on a struct containing only ULE fields, in the context of this impl) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are extra bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. OptionULE byte equality is semantic equality by relying on the ULE equality // invariant on the subfields unsafe impl ULE for OptionULE { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { let size = mem::size_of::(); if bytes.len() % size != 0 { return Err(UleError::length::(bytes.len())); @@ -88,7 +88,7 @@ unsafe impl ULE for OptionULE { return Err(UleError::parse::()); } } - 1 => U::validate_byte_slice(&chunk[1..])?, + 1 => U::validate_bytes(&chunk[1..])?, _ => return Err(UleError::parse::()), } } @@ -168,14 +168,14 @@ impl core::fmt::Debug for OptionVarULE // 1. OptionVarULE does not include any uninitialized or padding bytes // (achieved by being repr(C, packed) on ULE types) // 2. OptionVarULE is aligned to 1 byte (achieved by being repr(C, packed) on ULE types) -// 3. The impl of `validate_byte_slice()` returns an error if any byte is not valid. -// 4. The impl of `validate_byte_slice()` returns an error if the slice cannot be used in its entirety +// 3. The impl of `validate_bytes()` returns an error if any byte is not valid. +// 4. The impl of `validate_bytes()` returns an error if the slice cannot be used in its entirety // 5. The impl of `from_bytes_unchecked()` returns a reference to the same data. // 6. All other methods are defaulted // 7. OptionVarULE byte equality is semantic equality (achieved by being an aggregate) unsafe impl VarULE for OptionVarULE { #[inline] - fn validate_byte_slice(slice: &[u8]) -> Result<(), UleError> { + fn validate_bytes(slice: &[u8]) -> Result<(), UleError> { if slice.is_empty() { return Err(UleError::length::(slice.len())); } @@ -190,7 +190,7 @@ unsafe impl VarULE for OptionVarULE { Ok(()) } } - 1 => U::validate_byte_slice(&slice[1..]), + 1 => U::validate_bytes(&slice[1..]), _ => Err(UleError::parse::()), } } diff --git a/utils/zerovec/src/ule/plain.rs b/utils/zerovec/src/ule/plain.rs index 3d59706795c..4238263bfc6 100644 --- a/utils/zerovec/src/ule/plain.rs +++ b/utils/zerovec/src/ule/plain.rs @@ -36,13 +36,13 @@ impl RawBytesULE { // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) // 2. RawBytesULE is aligned to 1 byte. // (achieved by `#[repr(transparent)]` on a type that satisfies this invariant) -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid (never). -// 4. The impl of validate_byte_slice() returns an error if there are leftover bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid (never). +// 4. The impl of validate_bytes() returns an error if there are leftover bytes. // 5. The other ULE methods use the default impl. // 6. RawBytesULE byte equality is semantic equality unsafe impl ULE for RawBytesULE { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { if bytes.len() % N == 0 { // Safe because Self is transparent over [u8; N] Ok(()) @@ -182,13 +182,13 @@ impl_const_constructors!(bool, 1); // Safety (based on the safety checklist on the ULE trait): // 1. u8 does not include any uninitialized or padding bytes. // 2. u8 is aligned to 1 byte. -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid (never). -// 4. The impl of validate_byte_slice() returns an error if there are leftover bytes (never). +// 3. The impl of validate_bytes() returns an error if any byte is not valid (never). +// 4. The impl of validate_bytes() returns an error if there are leftover bytes (never). // 5. The other ULE methods use the default impl. // 6. u8 byte equality is semantic equality unsafe impl ULE for u8 { #[inline] - fn validate_byte_slice(_bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(_bytes: &[u8]) -> Result<(), UleError> { Ok(()) } } @@ -211,13 +211,13 @@ unsafe impl EqULE for u8 {} // Safety (based on the safety checklist on the ULE trait): // 1. NonZeroU8 does not include any uninitialized or padding bytes. // 2. NonZeroU8 is aligned to 1 byte. -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid (0x00). -// 4. The impl of validate_byte_slice() returns an error if there are leftover bytes (never). +// 3. The impl of validate_bytes() returns an error if any byte is not valid (0x00). +// 4. The impl of validate_bytes() returns an error if there are leftover bytes (never). // 5. The other ULE methods use the default impl. // 6. NonZeroU8 byte equality is semantic equality unsafe impl ULE for NonZeroU8 { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { bytes.iter().try_for_each(|b| { if *b == 0x00 { Err(UleError::parse::()) @@ -249,13 +249,13 @@ impl NicheBytes<1> for NonZeroU8 { // Safety (based on the safety checklist on the ULE trait): // 1. i8 does not include any uninitialized or padding bytes. // 2. i8 is aligned to 1 byte. -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid (never). -// 4. The impl of validate_byte_slice() returns an error if there are leftover bytes (never). +// 3. The impl of validate_bytes() returns an error if any byte is not valid (never). +// 4. The impl of validate_bytes() returns an error if there are leftover bytes (never). // 5. The other ULE methods use the default impl. // 6. i8 byte equality is semantic equality unsafe impl ULE for i8 { #[inline] - fn validate_byte_slice(_bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(_bytes: &[u8]) -> Result<(), UleError> { Ok(()) } } @@ -332,13 +332,13 @@ unsafe impl EqULE for f64 {} // Safety (based on the safety checklist on the ULE trait): // 1. bool does not include any uninitialized or padding bytes (the remaining 7 bytes in bool are by definition zero) // 2. bool is aligned to 1 byte. -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid (bytes that are not 0 or 1). -// 4. The impl of validate_byte_slice() returns an error if there are leftover bytes (never). +// 3. The impl of validate_bytes() returns an error if any byte is not valid (bytes that are not 0 or 1). +// 4. The impl of validate_bytes() returns an error if there are leftover bytes (never). // 5. The other ULE methods use the default impl. // 6. bool byte equality is semantic equality unsafe impl ULE for bool { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { for byte in bytes { // https://doc.rust-lang.org/reference/types/boolean.html // Rust booleans are always size 1, align 1 values with valid bit patterns 0x0 or 0x1 diff --git a/utils/zerovec/src/ule/slices.rs b/utils/zerovec/src/ule/slices.rs index 932ed5c6e00..8aa16ef2e93 100644 --- a/utils/zerovec/src/ule/slices.rs +++ b/utils/zerovec/src/ule/slices.rs @@ -7,15 +7,15 @@ use crate::ule::*; // Safety (based on the safety checklist on the ULE trait): // 1. [T; N] does not include any uninitialized or padding bytes since T is ULE // 2. [T; N] is aligned to 1 byte since T is ULE -// 3. The impl of validate_byte_slice() returns an error if any byte is not valid. -// 4. The impl of validate_byte_slice() returns an error if there are leftover bytes. +// 3. The impl of validate_bytes() returns an error if any byte is not valid. +// 4. The impl of validate_bytes() returns an error if there are leftover bytes. // 5. The other ULE methods use the default impl. // 6. [T; N] byte equality is semantic equality since T is ULE unsafe impl ULE for [T; N] { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { // a slice of multiple Selfs is equivalent to just a larger slice of Ts - T::validate_byte_slice(bytes) + T::validate_bytes(bytes) } } @@ -36,14 +36,14 @@ unsafe impl EqULE for [T; N] {} // Safety (based on the safety checklist on the VarULE trait): // 1. str does not include any uninitialized or padding bytes. // 2. str is aligned to 1 byte. -// 3. The impl of `validate_byte_slice()` returns an error if any byte is not valid. -// 4. The impl of `validate_byte_slice()` returns an error if the slice cannot be used in its entirety +// 3. The impl of `validate_bytes()` returns an error if any byte is not valid. +// 4. The impl of `validate_bytes()` returns an error if the slice cannot be used in its entirety // 5. The impl of `from_bytes_unchecked()` returns a reference to the same data. -// 6. `parse_bytes()` is equivalent to `validate_byte_slice()` followed by `from_bytes_unchecked()` +// 6. `parse_bytes()` is equivalent to `validate_bytes()` followed by `from_bytes_unchecked()` // 7. str byte equality is semantic equality unsafe impl VarULE for str { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { core::str::from_utf8(bytes).map_err(|_| UleError::parse::())?; Ok(()) } @@ -81,8 +81,8 @@ unsafe impl VarULE for str { // Safety (based on the safety checklist on the VarULE trait): // 1. [T] does not include any uninitialized or padding bytes (achieved by being a slice of a ULE type) // 2. [T] is aligned to 1 byte (achieved by being a slice of a ULE type) -// 3. The impl of `validate_byte_slice()` returns an error if any byte is not valid. -// 4. The impl of `validate_byte_slice()` returns an error if the slice cannot be used in its entirety +// 3. The impl of `validate_bytes()` returns an error if any byte is not valid. +// 4. The impl of `validate_bytes()` returns an error if the slice cannot be used in its entirety // 5. The impl of `from_bytes_unchecked()` returns a reference to the same data. // 6. All other methods are defaulted // 7. `[T]` byte equality is semantic equality (achieved by being a slice of a ULE type) @@ -91,8 +91,8 @@ where T: ULE, { #[inline] - fn validate_byte_slice(slice: &[u8]) -> Result<(), UleError> { - T::validate_byte_slice(slice) + fn validate_bytes(slice: &[u8]) -> Result<(), UleError> { + T::validate_bytes(slice) } #[inline] diff --git a/utils/zerovec/src/ule/tuple.rs b/utils/zerovec/src/ule/tuple.rs index 7ce810e4bce..cb7a710e393 100644 --- a/utils/zerovec/src/ule/tuple.rs +++ b/utils/zerovec/src/ule/tuple.rs @@ -39,13 +39,13 @@ macro_rules! tuple_ule { // (achieved by `#[repr(C, packed)]` on a struct containing only ULE fields) // 2. TupleULE is aligned to 1 byte. // (achieved by `#[repr(C, packed)]` on a struct containing only ULE fields) - // 3. The impl of validate_byte_slice() returns an error if any byte is not valid. - // 4. The impl of validate_byte_slice() returns an error if there are extra bytes. + // 3. The impl of validate_bytes() returns an error if any byte is not valid. + // 4. The impl of validate_bytes() returns an error if there are extra bytes. // 5. The other ULE methods use the default impl. // 6. TupleULE byte equality is semantic equality by relying on the ULE equality // invariant on the subfields unsafe impl<$($t: ULE),+> ULE for $name<$($t),+> { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { // expands to: 0size + mem::size_of::() + mem::size_of::(); let ule_bytes = 0usize $(+ mem::size_of::<$t>())+; if bytes.len() % ule_bytes != 0 { @@ -57,7 +57,7 @@ macro_rules! tuple_ule { let j = i; i += mem::size_of::<$t>(); #[allow(clippy::indexing_slicing)] // length checked - <$t>::validate_byte_slice(&chunk[j..i])?; + <$t>::validate_bytes(&chunk[j..i])?; )+ } Ok(()) diff --git a/utils/zerovec/src/ule/tuplevar.rs b/utils/zerovec/src/ule/tuplevar.rs index 18b2ffb2218..9863e974167 100644 --- a/utils/zerovec/src/ule/tuplevar.rs +++ b/utils/zerovec/src/ule/tuplevar.rs @@ -63,14 +63,14 @@ macro_rules! tuple_varule { // // 1. align(1): repr(transparent) around an align(1) VarULE type: MultiFieldsULE // 2. No padding: see previous point - // 3. `validate_byte_slice` validates that this type is a valid MultiFieldsULE, and that each field is the correct type from the tuple. - // 4. `validate_byte_slice` checks length by deferring to the inner ULEs + // 3. `validate_bytes` validates that this type is a valid MultiFieldsULE, and that each field is the correct type from the tuple. + // 4. `validate_bytes` checks length by deferring to the inner ULEs // 5. `from_bytes_unchecked` returns a fat pointer to the bytes. // 6. All other methods are left at their default impl. // 7. The inner ULEs have byte equality, so this composition has byte equality. unsafe impl<$($T: VarULE + ?Sized,)+ Format: VarZeroVecFormat> VarULE for $name<$($T,)+ Format> { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { // Safety: We validate that this type is the same kind of MultiFieldsULE (with $len, Format) // as in the type def let multi = as VarULE>::parse_bytes(bytes)?; @@ -89,7 +89,7 @@ macro_rules! tuple_varule { let multi = as VarULE>::from_bytes_unchecked(bytes); // This type is repr(transparent) over MultiFieldsULE<$len>, so its slices can be transmuted - // Field invariant upheld here: validate_byte_slice above validates every field for being the right type + // Field invariant upheld here: validate_bytes above validates every field for being the right type mem::transmute::<&MultiFieldsULE<$len, Format>, &Self>(multi) } } diff --git a/utils/zerovec/src/ule/vartuple.rs b/utils/zerovec/src/ule/vartuple.rs index 629adfed61a..30240cbe9a7 100644 --- a/utils/zerovec/src/ule/vartuple.rs +++ b/utils/zerovec/src/ule/vartuple.rs @@ -100,8 +100,8 @@ pub struct VarTupleULE { // // 1. align(1): see "Representation" above. // 2. No padding: see "Representation" above. -// 3. `validate_byte_slice` checks length and defers to the inner ULEs. -// 4. `validate_byte_slice` checks length and defers to the inner ULEs. +// 3. `validate_bytes` checks length and defers to the inner ULEs. +// 4. `validate_bytes` checks length and defers to the inner ULEs. // 5. `from_bytes_unchecked` returns a fat pointer to the bytes. // 6. All other methods are left at their default impl. // 7. The two ULEs have byte equality, so this composition has byte equality. @@ -110,14 +110,14 @@ where A: AsULE + 'static, V: VarULE + ?Sized, { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { // TODO: use split_first_chunk_mut in 1.77 if bytes.len() < size_of::() { return Err(UleError::length::(bytes.len())); } let (sized_chunk, variable_chunk) = bytes.split_at(size_of::()); - A::ULE::validate_byte_slice(sized_chunk)?; - V::validate_byte_slice(variable_chunk)?; + A::ULE::validate_bytes(sized_chunk)?; + V::validate_bytes(variable_chunk)?; Ok(()) } diff --git a/utils/zerovec/src/varzerovec/components.rs b/utils/zerovec/src/varzerovec/components.rs index d05b509894d..185b8eba528 100644 --- a/utils/zerovec/src/varzerovec/components.rs +++ b/utils/zerovec/src/varzerovec/components.rs @@ -692,7 +692,7 @@ where #[allow(clippy::indexing_slicing)] // Function contract allows panicky behavior let dat_slice = &mut output[dat_offset..dat_limit]; element.encode_var_ule_write(dat_slice); - debug_assert_eq!(T::validate_byte_slice(dat_slice), Ok(())); + debug_assert_eq!(T::validate_bytes(dat_slice), Ok(())); dat_offset = dat_limit; } diff --git a/utils/zerovec/src/varzerovec/slice.rs b/utils/zerovec/src/varzerovec/slice.rs index 2048dca7d35..42e66316f63 100644 --- a/utils/zerovec/src/varzerovec/slice.rs +++ b/utils/zerovec/src/varzerovec/slice.rs @@ -435,13 +435,13 @@ where // `[u8]` slice which satisfies this invariant) // 2. VarZeroSlice is aligned to 1 byte (achieved by `#[repr(transparent)]` on a // `[u8]` slice which satisfies this invariant) -// 3. The impl of `validate_byte_slice()` returns an error if any byte is not valid. -// 4. The impl of `validate_byte_slice()` returns an error if the slice cannot be used in its entirety +// 3. The impl of `validate_bytes()` returns an error if any byte is not valid. +// 4. The impl of `validate_bytes()` returns an error if the slice cannot be used in its entirety // 5. The impl of `from_bytes_unchecked()` returns a reference to the same data. // 6. `as_bytes()` is equivalent to a regular transmute of the underlying data // 7. VarZeroSlice byte equality is semantic equality (relying on the guideline of the underlying VarULE type) unsafe impl VarULE for VarZeroSlice { - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { let _: VarZeroVecComponents = VarZeroVecComponents::parse_bytes(bytes).map_err(|_| UleError::parse::())?; Ok(()) diff --git a/utils/zerovec/src/zerovec/mod.rs b/utils/zerovec/src/zerovec/mod.rs index d47202042cf..4d93ffa09f7 100644 --- a/utils/zerovec/src/zerovec/mod.rs +++ b/utils/zerovec/src/zerovec/mod.rs @@ -548,7 +548,7 @@ impl<'a, T: AsULE> ZeroVec<'a, T> { } Cow::Owned(old_vec) => { let bytes: &[u8] = T::ULE::as_bytes(&old_vec); - P::ULE::validate_byte_slice(bytes)?; + P::ULE::validate_bytes(bytes)?; // Feature "vec_into_raw_parts" is not yet stable (#65816). Polyfill: let (ptr, len, cap) = { // Take ownership of the pointer diff --git a/utils/zerovec/src/zerovec/slice.rs b/utils/zerovec/src/zerovec/slice.rs index 2eb68094f22..6ede6a7dd00 100644 --- a/utils/zerovec/src/zerovec/slice.rs +++ b/utils/zerovec/src/zerovec/slice.rs @@ -465,15 +465,15 @@ where // (`ZeroSlice` is a transparent wrapper around [T::ULE]) // 1. [T::ULE] does not include any uninitialized or padding bytes (achieved by being a slice of a ULE type) // 2. [T::ULE] is aligned to 1 byte (achieved by being a slice of a ULE type) -// 3. The impl of `validate_byte_slice()` returns an error if any byte is not valid. -// 4. The impl of `validate_byte_slice()` returns an error if the slice cannot be used in its entirety +// 3. The impl of `validate_bytes()` returns an error if any byte is not valid. +// 4. The impl of `validate_bytes()` returns an error if the slice cannot be used in its entirety // 5. The impl of `from_bytes_unchecked()` returns a reference to the same data. // 6. `as_bytes()` and `parse_bytes()` are defaulted // 7. `[T::ULE]` byte equality is semantic equality (relying on the guideline of the underlying `ULE` type) unsafe impl VarULE for ZeroSlice { #[inline] - fn validate_byte_slice(bytes: &[u8]) -> Result<(), UleError> { - T::ULE::validate_byte_slice(bytes) + fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { + T::ULE::validate_bytes(bytes) } #[inline]