diff --git a/components/locid/src/helpers.rs b/components/locid/src/helpers.rs index d12435fbf33..a29375a30cc 100644 --- a/components/locid/src/helpers.rs +++ b/components/locid/src/helpers.rs @@ -279,6 +279,58 @@ impl<'a, K: 'a, V: 'a> StoreIterable<'a, K, V> for ShortSlice<(K, V)> { } } +pub(crate) enum ShortSliceIntoIter { + ZeroOne(Option), + Multi(alloc::vec::IntoIter), +} + +impl Iterator for ShortSliceIntoIter { + type Item = T; + fn next(&mut self) -> Option { + match self { + Self::ZeroOne(option) => option.take(), + Self::Multi(into_iter) => into_iter.next(), + } + } +} + +impl IntoIterator for ShortSlice { + type Item = T; + type IntoIter = ShortSliceIntoIter; + + fn into_iter(self) -> Self::IntoIter { + match self { + ShortSlice::ZeroOne(option) => ShortSliceIntoIter::ZeroOne(option), + // TODO: Use a boxed slice IntoIter impl when available: + // + ShortSlice::Multi(boxed_slice) => { + ShortSliceIntoIter::Multi(boxed_slice.into_vec().into_iter()) + } + } + } +} + +impl<'a, K: 'a, V: 'a> StoreIterableMut<'a, K, V> for ShortSlice<(K, V)> { + type KeyValueIterMut = core::iter::Map< + core::slice::IterMut<'a, (K, V)>, + for<'r> fn(&'r mut (K, V)) -> (&'r K, &'r mut V), + >; + + type KeyValueIntoIter = ShortSliceIntoIter<(K, V)>; + + fn lm_iter_mut( + &'a mut self, + ) -> >::KeyValueIterMut { + self.iter_mut().map(|elt| (&elt.0, &mut elt.1)) + } + + fn lm_into_iter( + self, + ) -> >::KeyValueIntoIter { + self.into_iter() + } +} + impl StoreFromIterator for ShortSlice<(K, V)> {} #[test] @@ -286,6 +338,11 @@ fn test_short_slice_impl() { litemap::testing::check_store::>(); } +#[test] +fn test_short_slice_impl_full() { + litemap::testing::check_store_full::>(); +} + macro_rules! impl_tinystr_subtag { ( $(#[$doc:meta])*