#[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>

source

pub fn len(&self) -> usize

Return the number of key-value pairs in the map slice.

source

pub fn is_empty(&self) -> bool

Returns true if the map slice contains no elements.

source

pub fn get_index(&self, index: usize) -> Option<(&K, &V)>

Get a key-value pair by index.

Valid indices are 0 <= index < self.len()

source

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()

source

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()

source

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()

source

pub fn first(&self) -> Option<(&K, &V)>

Get the first key-value pair.

source

pub fn first_mut(&mut self) -> Option<(&K, &mut V)>

Get the first key-value pair, with mutable access to the value.

source

pub fn last(&self) -> Option<(&K, &V)>

Get the last key-value pair.

source

pub fn last_mut(&mut self) -> Option<(&K, &mut V)>

Get the last key-value pair, with mutable access to the value.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn iter(&self) -> Iter<'_, K, V>

Return an iterator over the key-value pairs of the map slice.

source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Return an iterator over the key-value pairs of the map slice.

source

pub fn keys(&self) -> Keys<'_, K, V>

Return an iterator over the keys of the map slice.

source

pub fn into_keys(self: Box<Slice<K, V>>) -> IntoKeys<K, V>

Return an owning iterator over the keys of the map slice.

source

pub fn values(&self) -> Values<'_, K, V>

Return an iterator over the values of the map slice.

source

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

Return an iterator over mutable references to the the values of the map slice.

source

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<K, V> Clone for Box<Slice<K, V>>
where K: Clone, V: Clone,

source§

fn clone(&self) -> Box<Slice<K, V>>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K, V> Debug for Slice<K, V>
where K: Debug, V: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<K, V> Default for &Slice<K, V>

source§

fn default() -> &Slice<K, V>

Returns the “default value” for a type. Read more
source§

impl<K, V> Default for &mut Slice<K, V>

source§

fn default() -> &mut Slice<K, V>

Returns the “default value” for a type. Read more
source§

impl<K, V> Default for Box<Slice<K, V>>

source§

fn default() -> Box<Slice<K, V>>

Returns the “default value” for a type. Read more
source§

impl<K, V> From<&Slice<K, V>> for Box<Slice<K, V>>
where K: Copy, V: Copy,

source§

fn from(slice: &Slice<K, V>) -> Box<Slice<K, V>>

Converts to this type from the input type.
source§

impl<K, V> Hash for Slice<K, V>
where K: Hash, V: Hash,

source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
source§

impl<K, V> Index<(Bound<usize>, Bound<usize>)> for Slice<K, V>

§

type Output = Slice<K, V>

The returned type after indexing.
source§

fn index(&self, range: (Bound<usize>, Bound<usize>)) -> &Slice<K, V>

Performs the indexing (container[index]) operation. Read more
source§

impl<K, V> Index<Range<usize>> for Slice<K, V>

§

type Output = Slice<K, V>

The returned type after indexing.
source§

fn index(&self, range: Range<usize>) -> &Slice<K, V>

Performs the indexing (container[index]) operation. Read more
source§

impl<K, V> Index<RangeFrom<usize>> for Slice<K, V>

§

type Output = Slice<K, V>

The returned type after indexing.
source§

fn index(&self, range: RangeFrom<usize>) -> &Slice<K, V>

Performs the indexing (container[index]) operation. Read more
source§

impl<K, V> Index<RangeFull> for Slice<K, V>

§

type Output = Slice<K, V>

The returned type after indexing.
source§

fn index(&self, range: RangeFull) -> &Slice<K, V>

Performs the indexing (container[index]) operation. Read more
source§

impl<K, V> Index<RangeInclusive<usize>> for Slice<K, V>

§

type Output = Slice<K, V>

The returned type after indexing.
source§

fn index(&self, range: RangeInclusive<usize>) -> &Slice<K, V>

Performs the indexing (container[index]) operation. Read more
source§

impl<K, V> Index<RangeTo<usize>> for Slice<K, V>

§

type Output = Slice<K, V>

The returned type after indexing.
source§

fn index(&self, range: RangeTo<usize>) -> &Slice<K, V>

Performs the indexing (container[index]) operation. Read more
source§

impl<K, V> Index<RangeToInclusive<usize>> for Slice<K, V>

§

type Output = Slice<K, V>

The returned type after indexing.
source§

fn index(&self, range: RangeToInclusive<usize>) -> &Slice<K, V>

Performs the indexing (container[index]) operation. Read more
source§

impl<K, V> Index<usize> for Slice<K, V>

§

type Output = V

The returned type after indexing.
source§

fn index(&self, index: usize) -> &V

Performs the indexing (container[index]) operation. Read more
source§

impl<K, V> IndexMut<(Bound<usize>, Bound<usize>)> for Slice<K, V>

source§

fn index_mut(&mut self, range: (Bound<usize>, Bound<usize>)) -> &mut Slice<K, V>

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<K, V> IndexMut<Range<usize>> for Slice<K, V>

source§

fn index_mut(&mut self, range: Range<usize>) -> &mut Slice<K, V>

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<K, V> IndexMut<RangeFrom<usize>> for Slice<K, V>

source§

fn index_mut(&mut self, range: RangeFrom<usize>) -> &mut Slice<K, V>

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<K, V> IndexMut<RangeFull> for Slice<K, V>

source§

fn index_mut(&mut self, range: RangeFull) -> &mut Slice<K, V>

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<K, V> IndexMut<RangeInclusive<usize>> for Slice<K, V>

source§

fn index_mut(&mut self, range: RangeInclusive<usize>) -> &mut Slice<K, V>

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<K, V> IndexMut<RangeTo<usize>> for Slice<K, V>

source§

fn index_mut(&mut self, range: RangeTo<usize>) -> &mut Slice<K, V>

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<K, V> IndexMut<RangeToInclusive<usize>> for Slice<K, V>

source§

fn index_mut(&mut self, range: RangeToInclusive<usize>) -> &mut Slice<K, V>

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<K, V> IndexMut<usize> for Slice<K, V>

source§

fn index_mut(&mut self, index: usize) -> &mut V

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<'a, K, V> IntoIterator for &'a Slice<K, V>

§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
source§

fn into_iter(self) -> <&'a Slice<K, V> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, K, V> IntoIterator for &'a mut Slice<K, V>

§

type IntoIter = IterMut<'a, K, V>

Which kind of iterator are we turning this into?
§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
source§

fn into_iter(self) -> <&'a mut Slice<K, V> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl<K, V> IntoIterator for Box<Slice<K, V>>

§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
§

type Item = (K, V)

The type of the elements being iterated over.
source§

fn into_iter(self) -> <Box<Slice<K, V>> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl<K, V> Ord for Slice<K, V>
where K: Ord, V: Ord,

source§

fn cmp(&self, other: &Slice<K, V>) -> Ordering

This method returns an Ordering between self and other. Read more
source§

impl<K, V> PartialEq for Slice<K, V>
where K: PartialEq, V: PartialEq,

source§

fn eq(&self, other: &Slice<K, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K, V> PartialOrd for Slice<K, V>
where K: PartialOrd, V: PartialOrd,

source§

fn partial_cmp(&self, other: &Slice<K, V>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<K, V> Serialize for Slice<K, V>
where K: Serialize, V: Serialize,

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,

Serialize this value into the given Serde serializer. Read more
source§

impl<K, V> Eq for Slice<K, V>
where K: Eq, V: Eq,

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for Slice<K, V>

§

impl<K, V> Send for Slice<K, V>
where K: Send, V: Send,

§

impl<K, V> !Sized for Slice<K, V>

§

impl<K, V> Sync for Slice<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for Slice<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for Slice<K, V>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more