// This file is part of ICU4X. For terms of use, please see the file // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). use super::*; type MapF = fn(&(K, V)) -> (&K, &V); #[inline] fn map_f(input: &(K, V)) -> (&K, &V) { (&input.0, &input.1) } impl<'a, K: 'a, V: 'a> StoreConstEmpty for &'a [(K, V)] { const EMPTY: &'a [(K, V)] = &[]; } impl<'a, K: 'a, V: 'a> Store for &'a [(K, V)] { #[inline] fn lm_len(&self) -> usize { self.len() } #[inline] fn lm_is_empty(&self) -> bool { self.is_empty() } #[inline] fn lm_get(&self, index: usize) -> Option<(&K, &V)> { self.get(index).map(map_f) } #[inline] fn lm_last(&self) -> Option<(&K, &V)> { self.last().map(map_f) } #[inline] fn lm_binary_search_by(&self, mut cmp: F) -> Result where F: FnMut(&K) -> Ordering, { self.binary_search_by(|(k, _)| cmp(k)) } } impl StoreSlice for &[(K, V)] { type Slice = [(K, V)]; fn lm_get_range(&self, range: Range) -> Option<&Self::Slice> { self.get(range) } } impl<'a, K: 'a, V: 'a> StoreIterable<'a, K, V> for &'a [(K, V)] { type KeyValueIter = core::iter::Map, MapF>; #[inline] fn lm_iter(&'a self) -> Self::KeyValueIter { self.iter().map(map_f) } }