Struct Slice
#[repr(transparent)]
pub struct Slice<K, V> { /* private fields */ }
A dynamically-sized slice of key-value pairs in an IndexMap.
This supports indexed operations much like a [(K, V)] slice,
but not any hashed operations on the map keys.
Unlike IndexMap, Slice does consider the order for PartialEq
and Eq, and it also implements PartialOrd, Ord, and Hash.
Implementations
impl<K, V> Slice<K, V>
const fn new<'a>() -> &'a SelfReturns an empty slice.
const fn new_mut<'a>() -> &'a mut SelfReturns an empty mutable slice.
const fn len(&self) -> usizeReturn the number of key-value pairs in the map slice.
const fn is_empty(&self) -> boolReturns true if the map slice contains no elements.
fn get_index(&self, index: usize) -> Option<(&K, &V)>Get a key-value pair by index.
Valid indices are
0 <= index < self.len().fn get_index_mut(&mut self, index: usize) -> Option<(&K, &mut V)>Get a key-value pair by index, with mutable access to the value.
Valid indices are
0 <= index < self.len().fn get_range<R: RangeBounds<usize>>(&self, range: R) -> Option<&Self>Returns a slice of key-value pairs in the given range of indices.
Valid indices are
0 <= index < self.len().fn get_range_mut<R: RangeBounds<usize>>(&mut self, range: R) -> Option<&mut Self>Returns a mutable slice of key-value pairs in the given range of indices.
Valid indices are
0 <= index < self.len().const fn first(&self) -> Option<(&K, &V)>Get the first key-value pair.
const fn first_mut(&mut self) -> Option<(&K, &mut V)>Get the first key-value pair, with mutable access to the value.
const fn last(&self) -> Option<(&K, &V)>Get the last key-value pair.
const fn last_mut(&mut self) -> Option<(&K, &mut V)>Get the last key-value pair, with mutable access to the value.
const fn split_at(&self, index: usize) -> (&Self, &Self)Divides one slice into two at an index.
Panics if
index > len. For a non-panicking alternative see [split_at_checked][Self::split_at_checked].const fn split_at_mut(&mut self, index: usize) -> (&mut Self, &mut Self)Divides one mutable slice into two at an index.
Panics if
index > len. For a non-panicking alternative see [split_at_mut_checked][Self::split_at_mut_checked].const fn split_at_checked(&self, index: usize) -> Option<(&Self, &Self)>Divides one slice into two at an index.
Returns
Noneifindex > len.const fn split_at_mut_checked(&mut self, index: usize) -> Option<(&mut Self, &mut Self)>Divides one mutable slice into two at an index.
Returns
Noneifindex > len.const fn split_first(&self) -> Option<((&K, &V), &Self)>Returns the first key-value pair and the rest of the slice, or
Noneif it is empty.const fn split_first_mut(&mut self) -> Option<((&K, &mut V), &mut Self)>Returns the first key-value pair and the rest of the slice, with mutable access to the value, or
Noneif it is empty.const fn split_last(&self) -> Option<((&K, &V), &Self)>Returns the last key-value pair and the rest of the slice, or
Noneif it is empty.const fn split_last_mut(&mut self) -> Option<((&K, &mut V), &mut Self)>Returns the last key-value pair and the rest of the slice, with mutable access to the value, or
Noneif it is empty.fn iter(&self) -> Iter<'_, K, V>Return an iterator over the key-value pairs of the map slice.
fn iter_mut(&mut self) -> IterMut<'_, K, V>Return an iterator over the key-value pairs of the map slice.
fn keys(&self) -> Keys<'_, K, V>Return an iterator over the keys of the map slice.
fn into_keys(self: Box<Self>) -> IntoKeys<K, V>Return an owning iterator over the keys of the map slice.
fn values(&self) -> Values<'_, K, V>Return an iterator over the values of the map slice.
fn values_mut(&mut self) -> ValuesMut<'_, K, V>Return an iterator over mutable references to the the values of the map slice.
fn into_values(self: Box<Self>) -> IntoValues<K, V>Return an owning iterator over the values of the map slice.
fn binary_search_keys(&self, x: &K) -> Result<usize, usize> where K: Ord,Search over a sorted map for a key.
Returns the position where that key is present, or the position where it can be inserted to maintain the sort. See
slice::binary_searchfor more details.Computes in O(log(n)) time, which is notably less scalable than looking the key up in the map this is a slice from using
IndexMap::get_index_of, but this can also position missing keys.fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize> where F: FnMut(&'a K, &'a V) -> Ordering,Search over a sorted map with a comparator function.
Returns the position where that value is present, or the position where it can be inserted to maintain the sort. See
slice::binary_search_byfor more details.Computes in O(log(n)) time.
fn binary_search_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<usize, usize> where F: FnMut(&'a K, &'a V) -> B, B: Ord,Search over a sorted map with an extraction function.
Returns the position where that value is present, or the position where it can be inserted to maintain the sort. See
slice::binary_search_by_keyfor more details.Computes in O(log(n)) time.
fn is_sorted(&self) -> bool where K: PartialOrd,Checks if the keys of this slice are sorted.
fn is_sorted_by<'a, F>(&'a self, cmp: F) -> bool where F: FnMut(&'a K, &'a V, &'a K, &'a V) -> bool,Checks if this slice is sorted using the given comparator function.
fn is_sorted_by_key<'a, F, T>(&'a self, sort_key: F) -> bool where F: FnMut(&'a K, &'a V) -> T, T: PartialOrd,Checks if this slice is sorted using the given sort-key function.
fn partition_point<P>(&self, pred: P) -> usize where P: FnMut(&K, &V) -> bool,Returns the index of the partition point of a sorted map according to the given predicate (the index of the first element of the second partition).
See
slice::partition_pointfor more details.Computes in O(log(n)) time.
fn get_disjoint_mut<const N: usize>(&mut self, indices: [usize; N]) -> Result<[(&K, &mut V); N], GetDisjointMutError>Get an array of
Nkey-value pairs byNindicesValid indices are 0 <= index < self.len() and each index needs to be unique.
Trait Implementations
impl<K, V> Index<(Bound<usize>, Bound<usize>)> for Slice<K, V>
type Output = Slice<K, V>;fn index(&self, range: (Bound<usize>, Bound<usize>)) -> &Self
impl<K, V> Index<Range<usize>> for Slice<K, V>
type Output = Slice<K, V>;fn index(&self, range: Range<usize>) -> &Self
impl<K, V> Index<RangeFrom<usize>> for Slice<K, V>
type Output = Slice<K, V>;fn index(&self, range: RangeFrom<usize>) -> &Self
impl<K, V> Index<RangeFull> for Slice<K, V>
type Output = Slice<K, V>;fn index(&self, range: RangeFull) -> &Self
impl<K, V> Index<RangeInclusive<usize>> for Slice<K, V>
type Output = Slice<K, V>;fn index(&self, range: RangeInclusive<usize>) -> &Self
impl<K, V> Index<RangeTo<usize>> for Slice<K, V>
type Output = Slice<K, V>;fn index(&self, range: RangeTo<usize>) -> &Self
impl<K, V> Index<RangeToInclusive<usize>> for Slice<K, V>
type Output = Slice<K, V>;fn index(&self, range: RangeToInclusive<usize>) -> &Self
impl<K, V> Index<usize> for Slice<K, V>
type Output = V;fn index(&self, index: usize) -> &V
impl<K, V> IndexMut<(Bound<usize>, Bound<usize>)> for Slice<K, V>
fn index_mut(&mut self, range: (Bound<usize>, Bound<usize>)) -> &mut Self
impl<K, V> IndexMut<Range<usize>> for Slice<K, V>
fn index_mut(&mut self, range: Range<usize>) -> &mut Self
impl<K, V> IndexMut<RangeFrom<usize>> for Slice<K, V>
fn index_mut(&mut self, range: RangeFrom<usize>) -> &mut Self
impl<K, V> IndexMut<RangeFull> for Slice<K, V>
fn index_mut(&mut self, range: RangeFull) -> &mut Self
impl<K, V> IndexMut<RangeInclusive<usize>> for Slice<K, V>
fn index_mut(&mut self, range: RangeInclusive<usize>) -> &mut Self
impl<K, V> IndexMut<RangeTo<usize>> for Slice<K, V>
fn index_mut(&mut self, range: RangeTo<usize>) -> &mut Self
impl<K, V> IndexMut<RangeToInclusive<usize>> for Slice<K, V>
fn index_mut(&mut self, range: RangeToInclusive<usize>) -> &mut Self
impl<K, V> IndexMut<usize> for Slice<K, V>
fn index_mut(&mut self, index: usize) -> &mut V
impl<K, V, K2, V2> PartialEq<Slice<K2, V2>> for Slice<K, V>
where
K: PartialEq<K2>,
V: PartialEq<V2>,
fn eq(&self, other: &Slice<K2, V2>) -> bool
impl<K, V, K2, V2> PartialEq<[(K2, V2)]> for Slice<K, V>
where
K: PartialEq<K2>,
V: PartialEq<V2>,
fn eq(&self, other: &[(K2, V2)]) -> bool
impl<K, V, K2, V2, const N: usize> PartialEq<[(K2, V2); N]> for Slice<K, V>
where
K: PartialEq<K2>,
V: PartialEq<V2>,
fn eq(&self, other: &[(K2, V2); N]) -> bool
impl<K: Debug, V: Debug> Debug for Slice<K, V>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<K: Eq, V: Eq> Eq for Slice<K, V>
impl<K: Hash, V: Hash> Hash for Slice<K, V>
fn hash<H: Hasher>(&self, state: &mut H)
impl<K: Ord, V: Ord> Ord for Slice<K, V>
fn cmp(&self, other: &Self) -> Ordering
impl<K: PartialOrd, V: PartialOrd> PartialOrd for Slice<K, V>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Auto Trait Implementations
impl<K, V> !Sized for Slice<K, V>
impl<K, V> Freeze for Slice<K, V>
where
[Bucket<K, V>]: Freeze,
impl<K, V> RefUnwindSafe for Slice<K, V>
where
[Bucket<K, V>]: RefUnwindSafe,
impl<K, V> Send for Slice<K, V>
where
[Bucket<K, V>]: Send,
impl<K, V> Sync for Slice<K, V>
where
[Bucket<K, V>]: Sync,
impl<K, V> Unpin for Slice<K, V>
where
[Bucket<K, V>]: Unpin,
impl<K, V> UnsafeUnpin for Slice<K, V>
where
[Bucket<K, V>]: UnsafeUnpin,
impl<K, V> UnwindSafe for Slice<K, V>
where
[Bucket<K, V>]: UnwindSafe,
Blanket Implementations
impl<Q, K> Comparable<K> for Slice<K, V>
where
Q: Ord + ?Sized,
K: Borrow<Q> + ?Sized,
fn compare(&self, key: &K) -> Ordering
impl<Q, K> Equivalent<K> for Slice<K, V>
where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
fn equivalent(&self, key: &K) -> bool
impl<Q, K> Equivalent<K> for Slice<K, V>
where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
fn equivalent(&self, key: &K) -> bool
impl<T> Any for Slice<K, V>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Slice<K, V>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Slice<K, V>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T