#[repr(transparent)]pub struct Slice<K, V> {
pub(crate) entries: [Bucket<K, V>],
}
Expand description
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
.
Fields§
§entries: [Bucket<K, V>]
Implementations§
source§impl<K, V> Slice<K, V>
impl<K, V> Slice<K, V>
sourcepub fn get_index(&self, index: usize) -> Option<(&K, &V)>
pub fn get_index(&self, index: usize) -> Option<(&K, &V)>
Get a key-value pair by index.
Valid indices are 0 <= index < self.len()
sourcepub fn get_index_mut(&mut self, index: usize) -> Option<(&K, &mut V)>
pub 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()
sourcepub fn get_range<R>(&self, range: R) -> Option<&Slice<K, V>>where
R: RangeBounds<usize>,
pub fn get_range<R>(&self, range: R) -> Option<&Slice<K, V>>where
R: RangeBounds<usize>,
Returns a slice of key-value pairs in the given range of indices.
Valid indices are 0 <= index < self.len()
sourcepub fn get_range_mut<R>(&mut self, range: R) -> Option<&mut Slice<K, V>>where
R: RangeBounds<usize>,
pub fn get_range_mut<R>(&mut self, range: R) -> Option<&mut Slice<K, V>>where
R: RangeBounds<usize>,
Returns a mutable slice of key-value pairs in the given range of indices.
Valid indices are 0 <= index < self.len()
sourcepub fn first_mut(&mut self) -> Option<(&K, &mut V)>
pub fn first_mut(&mut self) -> Option<(&K, &mut V)>
Get the first key-value pair, with mutable access to the value.
sourcepub fn last_mut(&mut self) -> Option<(&K, &mut V)>
pub fn last_mut(&mut self) -> Option<(&K, &mut V)>
Get the last key-value pair, with mutable access to the value.
sourcepub fn split_at(&self, index: usize) -> (&Slice<K, V>, &Slice<K, V>)
pub fn split_at(&self, index: usize) -> (&Slice<K, V>, &Slice<K, V>)
Divides one slice into two at an index.
Panics if index > len
.
sourcepub fn split_at_mut(
&mut self,
index: usize
) -> (&mut Slice<K, V>, &mut Slice<K, V>)
pub fn split_at_mut( &mut self, index: usize ) -> (&mut Slice<K, V>, &mut Slice<K, V>)
Divides one mutable slice into two at an index.
Panics if index > len
.
sourcepub fn split_first(&self) -> Option<((&K, &V), &Slice<K, V>)>
pub fn split_first(&self) -> Option<((&K, &V), &Slice<K, V>)>
Returns the first key-value pair and the rest of the slice,
or None
if it is empty.
sourcepub fn split_first_mut(&mut self) -> Option<((&K, &mut V), &mut Slice<K, V>)>
pub fn split_first_mut(&mut self) -> Option<((&K, &mut V), &mut Slice<K, V>)>
Returns the first key-value pair and the rest of the slice,
with mutable access to the value, or None
if it is empty.
sourcepub fn split_last(&self) -> Option<((&K, &V), &Slice<K, V>)>
pub fn split_last(&self) -> Option<((&K, &V), &Slice<K, V>)>
Returns the last key-value pair and the rest of the slice,
or None
if it is empty.
sourcepub fn split_last_mut(&mut self) -> Option<((&K, &mut V), &mut Slice<K, V>)>
pub fn split_last_mut(&mut self) -> Option<((&K, &mut V), &mut Slice<K, V>)>
Returns the last key-value pair and the rest of the slice,
with mutable access to the value, or None
if it is empty.
sourcepub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
Return an iterator over the key-value pairs of the map slice.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
Return an iterator over the key-value pairs of the map slice.
sourcepub fn into_keys(self: Box<Slice<K, V>>) -> IntoKeys<K, V> ⓘ
pub fn into_keys(self: Box<Slice<K, V>>) -> IntoKeys<K, V> ⓘ
Return an owning iterator over the keys of the map slice.
sourcepub fn values(&self) -> Values<'_, K, V> ⓘ
pub fn values(&self) -> Values<'_, K, V> ⓘ
Return an iterator over the values of the map slice.
sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V> ⓘ
Return an iterator over mutable references to the the values of the map slice.
sourcepub fn into_values(self: Box<Slice<K, V>>) -> IntoValues<K, V> ⓘ
pub fn into_values(self: Box<Slice<K, V>>) -> IntoValues<K, V> ⓘ
Return an owning iterator over the values of the map slice.
Trait Implementations§
source§impl<'a, K, V> IntoIterator for &'a Slice<K, V>
impl<'a, K, V> IntoIterator for &'a Slice<K, V>
source§impl<'a, K, V> IntoIterator for &'a mut Slice<K, V>
impl<'a, K, V> IntoIterator for &'a mut Slice<K, V>
source§impl<K, V> IntoIterator for Box<Slice<K, V>>
impl<K, V> IntoIterator for Box<Slice<K, V>>
source§impl<K, V> PartialEq for Slice<K, V>
impl<K, V> PartialEq for Slice<K, V>
source§impl<K, V> PartialOrd for Slice<K, V>where
K: PartialOrd,
V: PartialOrd,
impl<K, V> PartialOrd for Slice<K, V>where
K: PartialOrd,
V: PartialOrd,
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<K, V> Serialize for Slice<K, V>
impl<K, V> Serialize for Slice<K, V>
Serializes a map::Slice
as an ordered sequence.
This behaves like crate::serde_seq
for IndexMap
, serializing a sequence
of (key, value)
pairs, rather than as a map that might not preserve order.
Requires crate feature "serde"
source§fn serialize<T>(
&self,
serializer: T
) -> Result<<T as Serializer>::Ok, <T as Serializer>::Error>where
T: Serializer,
fn serialize<T>(
&self,
serializer: T
) -> Result<<T as Serializer>::Ok, <T as Serializer>::Error>where
T: Serializer,
impl<K, V> Eq for Slice<K, V>
Auto Trait Implementations§
impl<K, V> RefUnwindSafe for Slice<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for Slice<K, V>
impl<K, V> !Sized for Slice<K, V>
impl<K, V> Sync for Slice<K, V>
impl<K, V> Unpin for Slice<K, V>
impl<K, V> UnwindSafe for Slice<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.