diff --git a/components/collator/src/elements.rs b/components/collator/src/elements.rs index 08934ad383d..811877ad2f6 100644 --- a/components/collator/src/elements.rs +++ b/components/collator/src/elements.rs @@ -27,7 +27,7 @@ use icu_properties::CanonicalCombiningClass; use smallvec::SmallVec; use zerovec::ule::AsULE; use zerovec::ule::RawBytesULE; -use zerovec::ZeroSlice; +use zerovec::{zeroslice, ZeroSlice}; use crate::provider::CollationDataV1; @@ -147,17 +147,13 @@ pub(crate) const FFFD_CE: CollationElement = CollationElement(FFFD_CE_VALUE); pub(crate) const FFFD_CE32_VALUE: u32 = 0xFFFD0505; pub(crate) const FFFD_CE32: CollationElement32 = CollationElement32(FFFD_CE32_VALUE); -pub(crate) const EMPTY_U16: &ZeroSlice = - ZeroSlice::::from_ule_slice(&::ULE::from_array([])); +pub(crate) const EMPTY_U16: &ZeroSlice = zeroslice![]; const SINGLE_REPLACEMENT_CHARACTER_U16: &ZeroSlice = - ZeroSlice::::from_ule_slice(&::ULE::from_array([ - REPLACEMENT_CHARACTER as u16 - ])); - -pub(crate) const EMPTY_CHAR: &ZeroSlice = ZeroSlice::new_empty(); + zeroslice![u16; ::ULE::from_unsigned; REPLACEMENT_CHARACTER as u16]; +pub(crate) const EMPTY_CHAR: &ZeroSlice = zeroslice![]; const SINGLE_REPLACEMENT_CHARACTER_CHAR: &ZeroSlice = - ZeroSlice::::from_ule_slice(&::ULE::from_array([REPLACEMENT_CHARACTER])); + zeroslice![char; ::ULE::from_aligned; REPLACEMENT_CHARACTER]; /// If `opt` is `Some`, unwrap it. If `None`, panic if debug assertions /// are enabled and return `default` if debug assertions are not enabled. diff --git a/components/collator/src/provider.rs b/components/collator/src/provider.rs index ad35fa4d5cd..d7c83d8f307 100644 --- a/components/collator/src/provider.rs +++ b/components/collator/src/provider.rs @@ -22,8 +22,8 @@ use icu_collections::char16trie::Char16TrieIterator; use icu_collections::codepointtrie::CodePointTrie; use icu_provider::prelude::*; use zerovec::ule::AsULE; -use zerovec::ZeroSlice; use zerovec::ZeroVec; +use zerovec::{zeroslice, ZeroSlice}; use crate::elements::CollationElement; use crate::elements::CollationElement32; @@ -39,9 +39,9 @@ use super::CaseFirst; use super::MaxVariable; const SINGLE_U32: &ZeroSlice = - ZeroSlice::::from_ule_slice(&::ULE::from_array([FFFD_CE32_VALUE])); + zeroslice![u32; ::ULE::from_unsigned; FFFD_CE32_VALUE]; const SINGLE_U64: &ZeroSlice = - ZeroSlice::::from_ule_slice(&::ULE::from_array([FFFD_CE_VALUE])); + zeroslice![u64; ::ULE::from_unsigned; FFFD_CE_VALUE]; fn data_ce_to_primary(data_ce: u64, c: char) -> u32 { // Collation::getThreeBytePrimaryForOffsetData diff --git a/components/collections/src/codepointinvlist/cpinvlist.rs b/components/collections/src/codepointinvlist/cpinvlist.rs index 4e9f20299ec..6d95416ea21 100644 --- a/components/collections/src/codepointinvlist/cpinvlist.rs +++ b/components/collections/src/codepointinvlist/cpinvlist.rs @@ -8,7 +8,7 @@ use alloc::vec::Vec; use core::{char, ops::RangeBounds, ops::RangeInclusive}; use yoke::Yokeable; use zerofrom::ZeroFrom; -use zerovec::{ule::AsULE, ZeroSlice, ZeroVec}; +use zerovec::{ule::AsULE, zerovec, ZeroVec}; use super::CodePointInversionListError; use crate::codepointinvlist::utils::{deconstruct_range, is_valid_zv}; @@ -17,15 +17,12 @@ use crate::codepointinvlist::utils::{deconstruct_range, is_valid_zv}; const BMP_MAX: u32 = 0xFFFF; /// Represents the inversion list for a set of all code points in the Basic Multilingual Plane. -const BMP_INV_LIST_SLICE: &ZeroSlice = - ZeroSlice::::from_ule_slice(&::ULE::from_array([0x0, BMP_MAX + 1])); +const BMP_INV_LIST_VEC: ZeroVec = + zerovec![u32; ::ULE::from_unsigned; 0x0, BMP_MAX + 1]; /// Represents the inversion list for all of the code points in the Unicode range. -const ALL_SLICE: &ZeroSlice = - ZeroSlice::::from_ule_slice(&::ULE::from_array([ - 0x0, - (char::MAX as u32) + 1, - ])); +const ALL_VEC: ZeroVec = + zerovec![u32; ::ULE::from_unsigned; 0x0, (char::MAX as u32) + 1]; /// A membership wrapper for [`CodePointInversionList`]. /// @@ -297,7 +294,7 @@ impl<'data> CodePointInversionList<'data> { /// ``` pub fn all() -> Self { Self { - inv_list: ALL_SLICE.as_zerovec(), + inv_list: ALL_VEC, size: (char::MAX as usize) + 1, } } @@ -326,7 +323,7 @@ impl<'data> CodePointInversionList<'data> { /// ``` pub fn bmp() -> Self { Self { - inv_list: BMP_INV_LIST_SLICE.as_zerovec(), + inv_list: BMP_INV_LIST_VEC, size: (BMP_MAX as usize) + 1, } } diff --git a/components/collections/src/codepointtrie/benches/codepointtrie.rs b/components/collections/src/codepointtrie/benches/codepointtrie.rs index 6cf38a704dd..5117330752a 100644 --- a/components/collections/src/codepointtrie/benches/codepointtrie.rs +++ b/components/collections/src/codepointtrie/benches/codepointtrie.rs @@ -33,8 +33,8 @@ fn one_hundred_code_points(sample_str: &str) -> String { fn get_trie_small() -> CodePointTrie<'static, u8> { CodePointTrie::try_new( tries::gc_small::HEADER, - tries::gc_small::INDEX.as_zerovec(), - tries::gc_small::DATA.as_zerovec(), + tries::gc_small::INDEX, + tries::gc_small::DATA, ) .unwrap() } @@ -43,8 +43,8 @@ fn get_trie_small() -> CodePointTrie<'static, u8> { fn get_trie_fast() -> CodePointTrie<'static, u8> { CodePointTrie::try_new( tries::gc_fast::HEADER, - tries::gc_fast::INDEX.as_zerovec(), - tries::gc_fast::DATA.as_zerovec(), + tries::gc_fast::INDEX, + tries::gc_fast::DATA, ) .unwrap() } diff --git a/components/collections/src/codepointtrie/benches/iai_cpt.rs b/components/collections/src/codepointtrie/benches/iai_cpt.rs index 63818019a03..3d57cbb4a16 100644 --- a/components/collections/src/codepointtrie/benches/iai_cpt.rs +++ b/components/collections/src/codepointtrie/benches/iai_cpt.rs @@ -14,8 +14,8 @@ const SAMPLE_STRING_MIXED: &str = "Dèclaråcion ЗАГАЛЬНА 世界人权 fn get_trie_small() -> CodePointTrie<'static, u8> { CodePointTrie::try_new( tries::gc_small::HEADER, - tries::gc_small::INDEX.as_zerovec(), - tries::gc_small::DATA.as_zerovec(), + tries::gc_small::INDEX, + tries::gc_small::DATA, ) .unwrap() } @@ -23,8 +23,8 @@ fn get_trie_small() -> CodePointTrie<'static, u8> { fn get_trie_fast() -> CodePointTrie<'static, u8> { CodePointTrie::try_new( tries::gc_fast::HEADER, - tries::gc_fast::INDEX.as_zerovec(), - tries::gc_fast::DATA.as_zerovec(), + tries::gc_fast::INDEX, + tries::gc_fast::DATA, ) .unwrap() } diff --git a/components/collections/src/codepointtrie/benches/tries/gc_fast.rs b/components/collections/src/codepointtrie/benches/tries/gc_fast.rs index 3d81c241681..ba25814cb31 100644 --- a/components/collections/src/codepointtrie/benches/tries/gc_fast.rs +++ b/components/collections/src/codepointtrie/benches/tries/gc_fast.rs @@ -3,10 +3,11 @@ // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). use icu_collections::codepointtrie::{CodePointTrieHeader, TrieType}; -use zerovec::{ule::RawBytesULE, ZeroSlice}; +use zerovec::ule::AsULE; +use zerovec::{zerovec, ZeroVec}; #[rustfmt::skip] -pub static INDEX: &ZeroSlice = ZeroSlice::::from_ule_slice(&RawBytesULE::<2>::from_array([ +pub const INDEX: ZeroVec = zerovec![u16; ::ULE::from_unsigned; 0,0x40,0x7f,0xbf,0xff,0x12e,0x16d,0x1ad,0x1e5,0x224,0x250,0x28e,0x2ce,0x2de,0x31e,0x34f, 0x38c,0x3bc,0x3fa,0x43a,0x44a,0x47b,0x4b2,0x4f2,0x532,0x572,0x5a3,0x5cf,0x60f,0x644,0x65e,0x69e, 0x6de,0x71e,0x756,0x78d,0x7ca,0x809,0x848,0x887,0x8c6,0x905,0x944,0x983,0x9c3,0xa01,0xa3f,0xa7f, @@ -198,10 +199,10 @@ pub static INDEX: &ZeroSlice = ZeroSlice::::from_ule_slice(&RawBytesUL 0x66a,0x66a,0x66a,0x66a,0x66a,0x66a,0x66a,0x66a,0x66a,0x66a,0x66a,0x66a,0x66a,0x66a,0x380,0x380, 0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380, 0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0x380,0xaa0 -])); +]; #[rustfmt::skip] -pub static DATA: &ZeroSlice = ZeroSlice::::from_ule_slice(&[ +pub const DATA: ZeroVec = zerovec![u8; core::convert::identity; 0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf, 0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf, 0xc,0x17,0x17,0x17,0x19,0x17,0x17,0x17,0x14,0x15,0x17,0x18,0x17,0x13,0x17,0x17, @@ -1111,7 +1112,7 @@ pub static DATA: &ZeroSlice = ZeroSlice::::from_ule_slice(&[ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x11,0x11, 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0,0 -]); +]; pub static HEADER: CodePointTrieHeader = CodePointTrieHeader { high_start: 0x110000, diff --git a/components/collections/src/codepointtrie/benches/tries/gc_small.rs b/components/collections/src/codepointtrie/benches/tries/gc_small.rs index 0e09435ec93..26b30d444b1 100644 --- a/components/collections/src/codepointtrie/benches/tries/gc_small.rs +++ b/components/collections/src/codepointtrie/benches/tries/gc_small.rs @@ -3,10 +3,11 @@ // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). use icu_collections::codepointtrie::{CodePointTrieHeader, TrieType}; -use zerovec::{ule::RawBytesULE, ZeroSlice}; +use zerovec::ule::AsULE; +use zerovec::{zerovec, ZeroVec}; #[rustfmt::skip] -pub static INDEX: &ZeroSlice = ZeroSlice::::from_ule_slice(&RawBytesULE::<2>::from_array([ +pub const INDEX: ZeroVec = zerovec![u16; ::ULE::from_unsigned; 0,0x40,0x7f,0xbf,0xff,0x12e,0x16d,0x1ad,0x1e5,0x224,0x250,0x28e,0x2ce,0x2de,0x31e,0x34f, 0x38c,0x3bc,0x3fa,0x43a,0x44a,0x47b,0x4b2,0x4f2,0x532,0x572,0x5a3,0x5cf,0x60f,0x644,0x65e,0x69e, 0x6de,0x71e,0x756,0x78d,0x7ca,0x809,0x848,0x887,0x8c6,0x905,0x944,0x983,0x9c3,0xa01,0xa3f,0xa7f, @@ -220,10 +221,10 @@ pub static INDEX: &ZeroSlice = ZeroSlice::::from_ule_slice(&RawBytesUL 0x767,0x767,0x767,0x767,0x767,0x767,0x767,0x767,0x767,0x767,0x767,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5, 0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5, 0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0x4b5,0xb9d -])); +]; #[rustfmt::skip] -pub static DATA: &ZeroSlice = ZeroSlice::::from_ule_slice(&[ +pub const DATA: ZeroVec = zerovec![u8; core::convert::identity; 0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf, 0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf,0xf, 0xc,0x17,0x17,0x17,0x19,0x17,0x17,0x17,0x14,0x15,0x17,0x18,0x17,0x13,0x17,0x17, @@ -848,7 +849,7 @@ pub static DATA: &ZeroSlice = ZeroSlice::::from_ule_slice(&[ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x10,0x10, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x11,0x11, 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0,0,0,0 -]); +]; pub static HEADER: CodePointTrieHeader = CodePointTrieHeader { high_start: 0x110000, diff --git a/components/normalizer/src/lib.rs b/components/normalizer/src/lib.rs index cc46b088b46..0eadd9bdc11 100644 --- a/components/normalizer/src/lib.rs +++ b/components/normalizer/src/lib.rs @@ -101,8 +101,7 @@ use utf16_iter::Utf16CharsEx; use utf8_iter::Utf8CharsEx; use write16::Write16; use zerofrom::ZeroFrom; -use zerovec::ule::AsULE; -use zerovec::ZeroSlice; +use zerovec::{zeroslice, ZeroSlice}; #[derive(Debug)] enum SupplementPayloadHolder { @@ -244,10 +243,9 @@ fn char_from_u16(u: u16) -> char { char_from_u32(u32::from(u)) } -const EMPTY_U16: &ZeroSlice = - ZeroSlice::::from_ule_slice(&::ULE::from_array([])); +const EMPTY_U16: &ZeroSlice = zeroslice![]; -const EMPTY_CHAR: &ZeroSlice = ZeroSlice::new_empty(); +const EMPTY_CHAR: &ZeroSlice = zeroslice![]; #[inline(always)] fn in_inclusive_range(c: char, start: char, end: char) -> bool { diff --git a/utils/zerovec/src/ule/plain.rs b/utils/zerovec/src/ule/plain.rs index dc8e4510e0a..f244f6b6825 100644 --- a/utils/zerovec/src/ule/plain.rs +++ b/utils/zerovec/src/ule/plain.rs @@ -111,7 +111,7 @@ macro_rules! impl_const_constructors { } macro_rules! impl_byte_slice_type { - ($type:ty, $size:literal) => { + ($single_fn:ident, $type:ty, $size:literal) => { impl From<$type> for RawBytesULE<$size> { #[inline] fn from(value: $type) -> Self { @@ -132,6 +132,24 @@ macro_rules! impl_byte_slice_type { // EqULE is true because $type and RawBytesULE<$size> // have the same byte sequence on little-endian unsafe impl EqULE for $type {} + + impl RawBytesULE<$size> { + pub const fn $single_fn(v: $type) -> Self { + RawBytesULE(v.to_le_bytes()) + } + } + }; +} + +macro_rules! impl_byte_slice_unsigned_type { + ($type:ty, $size:literal) => { + impl_byte_slice_type!(from_unsigned, $type, $size); + }; +} + +macro_rules! impl_byte_slice_signed_type { + ($type:ty, $size:literal) => { + impl_byte_slice_type!(from_signed, $type, $size); }; } @@ -140,15 +158,15 @@ impl_byte_slice_size!(u32, 4); impl_byte_slice_size!(u64, 8); impl_byte_slice_size!(u128, 16); -impl_byte_slice_type!(u16, 2); -impl_byte_slice_type!(u32, 4); -impl_byte_slice_type!(u64, 8); -impl_byte_slice_type!(u128, 16); +impl_byte_slice_unsigned_type!(u16, 2); +impl_byte_slice_unsigned_type!(u32, 4); +impl_byte_slice_unsigned_type!(u64, 8); +impl_byte_slice_unsigned_type!(u128, 16); -impl_byte_slice_type!(i16, 2); -impl_byte_slice_type!(i32, 4); -impl_byte_slice_type!(i64, 8); -impl_byte_slice_type!(i128, 16); +impl_byte_slice_signed_type!(i16, 2); +impl_byte_slice_signed_type!(i32, 4); +impl_byte_slice_signed_type!(i64, 8); +impl_byte_slice_signed_type!(i128, 16); impl_const_constructors!(u8, 1); impl_const_constructors!(u16, 2); diff --git a/utils/zerovec/src/ule/unvalidated.rs b/utils/zerovec/src/ule/unvalidated.rs index 33a8656a7df..21cfb0c0d58 100644 --- a/utils/zerovec/src/ule/unvalidated.rs +++ b/utils/zerovec/src/ule/unvalidated.rs @@ -322,6 +322,15 @@ impl UnvalidatedChar { } } +impl RawBytesULE<3> { + /// Converts a [`UnvalidatedChar`] to its ULE type. This is equivalent to calling + /// [`AsULE::to_unaligned`]. + #[inline] + pub const fn from_unvalidated_char(uc: UnvalidatedChar) -> Self { + RawBytesULE(uc.0) + } +} + impl AsULE for UnvalidatedChar { type ULE = RawBytesULE<3>; diff --git a/utils/zerovec/src/zerovec/mod.rs b/utils/zerovec/src/zerovec/mod.rs index 9f1c439cd4f..a36b53289dd 100644 --- a/utils/zerovec/src/zerovec/mod.rs +++ b/utils/zerovec/src/zerovec/mod.rs @@ -919,14 +919,14 @@ impl FromIterator for ZeroVec<'_, T> { } } -/// Convenience wrapper for [`ZeroSlice::from_ule_slice`]. The value will be created at compile-time. +/// Convenience wrapper for [`ZeroSlice::from_ule_slice`]. The value will be created at compile-time, +/// meaning that all arguments must also be constant. /// /// # Arguments /// /// * `$aligned` - The type of an element in its canonical, aligned form, e.g., `char`. -/// * `$array_fn` - A const function that converts an array of `$aligned` elements into an array -/// of their unaligned equivalents, e.g., -/// `const fn from_array(arr: [char; N]) -> [::ULE; N]`. +/// * `$convert` - A const function that converts an `$aligned` into its unaligned equivalent, e.g., +/// `const fn from_aligned(a: CanonicalType) -> CanonicalType::ULE`. /// * `$x` - The elements that the `ZeroSlice` will hold. /// /// # Examples @@ -935,47 +935,48 @@ impl FromIterator for ZeroVec<'_, T> { /// /// ``` /// use zerovec::{ZeroSlice, zeroslice, ule::AsULE}; +/// use zerovec::ule::UnvalidatedChar; /// -/// const SIGNATURE: &ZeroSlice = zeroslice![char; ::ULE::from_array; 'b', 'y', 'e', '✌']; +/// const SIGNATURE: &ZeroSlice = zeroslice![char; ::ULE::from_aligned; 'b', 'y', 'e', '✌']; /// const EMPTY: &ZeroSlice = zeroslice![]; +/// const UC: &ZeroSlice = +/// zeroslice![ +/// UnvalidatedChar; +/// ::ULE::from_unvalidated_char; +/// UnvalidatedChar::from_char('a'), +/// ]; /// let empty: &ZeroSlice = zeroslice![]; -/// let nums = zeroslice![u32; ::ULE::from_array; 1, 2, 3, 4, 5]; +/// let nums = zeroslice![u32; ::ULE::from_unsigned; 1, 2, 3, 4, 5]; /// assert_eq!(nums.last().unwrap(), 5); /// ``` /// /// Using a custom array-conversion function: /// /// ``` -/// use zerovec::{ZeroSlice, zeroslice}; +/// use zerovec::{ZeroSlice, zeroslice, ule::AsULE, ule::RawBytesULE}; /// -/// mod conversion { -/// use zerovec::ule::RawBytesULE; -/// pub(super) const fn i16_array_to_be_array(arr: [i16; N]) -> [RawBytesULE<2>; N] { -/// let mut result = [RawBytesULE([0; 2]); N]; -/// let mut i = 0; -/// while i < N { -/// result[i] = RawBytesULE(arr[i].to_be_bytes()); -/// i += 1; -/// } -/// result -/// } +/// const fn be_convert(num: i16) -> ::ULE { +/// RawBytesULE(num.to_be_bytes()) /// } /// -/// const NUMBERS: &ZeroSlice = zeroslice![i16; conversion::i16_array_to_be_array; 1, -2, 3, -4, 5]; +/// const NUMBERS_BE: &ZeroSlice = zeroslice![i16; be_convert; 1, -2, 3, -4, 5]; /// ``` #[macro_export] macro_rules! zeroslice { () => ( $crate::ZeroSlice::new_empty() ); - ($aligned:ty; $array_fn:expr; $($x:expr),+ $(,)?) => ( + ($aligned:ty; $convert:expr; $($x:expr),+ $(,)?) => ( $crate::ZeroSlice::<$aligned>::from_ule_slice( - {const X: &[<$aligned as $crate::ule::AsULE>::ULE] = &$array_fn([$($x),+]); X} + {const X: &[<$aligned as $crate::ule::AsULE>::ULE] = &[ + $($convert($x)),* + ]; X} ) ); } -/// Creates a borrowed `ZeroVec`. Convenience wrapper for `zeroslice![...].as_zerovec()`. +/// Creates a borrowed `ZeroVec`. Convenience wrapper for `zeroslice![...].as_zerovec()`. The value +/// will be created at compile-time, meaning that all arguments must also be constant. /// /// See [`zeroslice!`](crate::zeroslice) for more information. /// @@ -984,7 +985,7 @@ macro_rules! zeroslice { /// ``` /// use zerovec::{ZeroVec, zerovec, ule::AsULE}; /// -/// const SIGNATURE: ZeroVec = zerovec![char; ::ULE::from_array; 'a', 'y', 'e', '✌']; +/// const SIGNATURE: ZeroVec = zerovec![char; ::ULE::from_aligned; 'a', 'y', 'e', '✌']; /// assert!(!SIGNATURE.is_owned()); /// /// const EMPTY: ZeroVec = zerovec![]; @@ -995,8 +996,8 @@ macro_rules! zerovec { () => ( $crate::ZeroVec::new() ); - ($aligned:ty; $array_fn:expr; $($x:expr),+ $(,)?) => ( - $crate::zeroslice![$aligned; $array_fn; $($x),+].as_zerovec() + ($aligned:ty; $convert:expr; $($x:expr),+ $(,)?) => ( + $crate::zeroslice![$aligned; $convert; $($x),+].as_zerovec() ); } diff --git a/utils/zerovec/src/zerovec/slice.rs b/utils/zerovec/src/zerovec/slice.rs index 52ddc184b30..493dd3d56a5 100644 --- a/utils/zerovec/src/zerovec/slice.rs +++ b/utils/zerovec/src/zerovec/slice.rs @@ -567,6 +567,7 @@ where #[cfg(test)] mod test { use super::*; + use crate::zeroslice; #[test] fn test_split_first() { @@ -576,21 +577,16 @@ mod test { } { // single element slice - const DATA: &ZeroSlice = - ZeroSlice::::from_ule_slice(&::ULE::from_array([211])); - assert_eq!((211, ZeroSlice::new_empty()), DATA.split_first().unwrap()); + const DATA: &ZeroSlice = zeroslice![u16; ::ULE::from_unsigned; 211]; + assert_eq!((211, zeroslice![]), DATA.split_first().unwrap()); } { // slice with many elements. const DATA: &ZeroSlice = - ZeroSlice::::from_ule_slice(&::ULE::from_array([ - 211, 281, 421, 32973, - ])); + zeroslice![u16; ::ULE::from_unsigned; 211, 281, 421, 32973]; const EXPECTED_VALUE: (u16, &ZeroSlice) = ( 211, - ZeroSlice::::from_ule_slice(&::ULE::from_array([ - 281, 421, 32973, - ])), + zeroslice![u16; ::ULE::from_unsigned; 281, 421, 32973], ); assert_eq!(EXPECTED_VALUE, DATA.split_first().unwrap());