diff options
Diffstat (limited to 'vendor/litemap/src/store')
-rw-r--r-- | vendor/litemap/src/store/mod.rs | 11 | ||||
-rw-r--r-- | vendor/litemap/src/store/slice_impl.rs | 8 | ||||
-rw-r--r-- | vendor/litemap/src/store/vec_impl.rs | 8 |
3 files changed, 25 insertions, 2 deletions
diff --git a/vendor/litemap/src/store/mod.rs b/vendor/litemap/src/store/mod.rs index 3468ebb97..ca696a1af 100644 --- a/vendor/litemap/src/store/mod.rs +++ b/vendor/litemap/src/store/mod.rs @@ -30,6 +30,7 @@ use core::cmp::Ordering; use core::iter::DoubleEndedIterator; use core::iter::FromIterator; use core::iter::Iterator; +use core::ops::Range; /// Trait to enable const construction of empty store. pub trait StoreConstEmpty<K: ?Sized, V: ?Sized> { @@ -53,7 +54,7 @@ pub trait Store<K: ?Sized, V: ?Sized>: Sized { /// Gets a key/value pair at the specified index. fn lm_get(&self, index: usize) -> Option<(&K, &V)>; - /// Gets the last element in the store, or None if the store is empty. + /// Gets the last element in the store, or `None` if the store is empty. fn lm_last(&self) -> Option<(&K, &V)> { let len = self.lm_len(); if len == 0 { @@ -76,6 +77,12 @@ pub trait StoreFromIterable<K, V>: Store<K, V> { fn lm_sort_from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self; } +pub trait StoreSlice<K: ?Sized, V: ?Sized>: Store<K, V> { + type Slice: ?Sized; + + fn lm_get_range(&self, range: Range<usize>) -> Option<&Self::Slice>; +} + pub trait StoreMut<K, V>: Store<K, V> { /// Creates a new store with the specified capacity hint. /// @@ -129,7 +136,7 @@ pub trait StoreMut<K, V>: Store<K, V> { } /// Iterator methods for the LiteMap store. -pub trait StoreIterable<'a, K: 'a, V: 'a>: Store<K, V> { +pub trait StoreIterable<'a, K: 'a + ?Sized, V: 'a + ?Sized>: Store<K, V> { type KeyValueIter: Iterator<Item = (&'a K, &'a V)> + DoubleEndedIterator + 'a; /// Returns an iterator over key/value pairs. diff --git a/vendor/litemap/src/store/slice_impl.rs b/vendor/litemap/src/store/slice_impl.rs index 4afb4fac2..48f6ca40c 100644 --- a/vendor/litemap/src/store/slice_impl.rs +++ b/vendor/litemap/src/store/slice_impl.rs @@ -45,6 +45,14 @@ impl<'a, K: 'a, V: 'a> Store<K, V> for &'a [(K, V)] { } } +impl<'a, K, V> StoreSlice<K, V> for &'a [(K, V)] { + type Slice = [(K, V)]; + + fn lm_get_range(&self, range: Range<usize>) -> 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<core::slice::Iter<'a, (K, V)>, MapF<K, V>>; diff --git a/vendor/litemap/src/store/vec_impl.rs b/vendor/litemap/src/store/vec_impl.rs index 361b926c3..2205e8e8f 100644 --- a/vendor/litemap/src/store/vec_impl.rs +++ b/vendor/litemap/src/store/vec_impl.rs @@ -53,6 +53,14 @@ impl<K, V> Store<K, V> for Vec<(K, V)> { } } +impl<K, V> StoreSlice<K, V> for Vec<(K, V)> { + type Slice = [(K, V)]; + + fn lm_get_range(&self, range: Range<usize>) -> Option<&Self::Slice> { + self.get(range) + } +} + impl<K, V> StoreMut<K, V> for Vec<(K, V)> { #[inline] fn lm_with_capacity(capacity: usize) -> Self { |