indexmap::map

Struct Slice

Source
pub struct Slice<K, V> { /* private fields */ }
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.

Implementations§

Source§

impl<K, V> Slice<K, V>

Source

pub const fn new<'a>() -> &'a Self

Returns an empty slice.

Source

pub fn new_mut<'a>() -> &'a mut Self

Returns an empty mutable slice.

Source

pub const fn len(&self) -> usize

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

Source

pub const 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: 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().

Source

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

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) -> (&Self, &Self)

Divides one slice into two at an index.

Panics if index > len.

Source

pub 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.

Source

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

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

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), &Self)>

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

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<Self>) -> 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<Self>) -> IntoValues<K, V>

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

Source

pub 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_search for 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.

Source

pub 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_by for more details.

Computes in O(log(n)) time.

Source

pub 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_key for more details.

Computes in O(log(n)) time.

Source

pub 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_point for more details.

Computes in O(log(n)) time.

Trait Implementations§

Source§

impl<K: Clone, V: Clone> Clone for Box<Slice<K, V>>

Source§

fn clone(&self) -> Self

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: Debug, V: Debug> Debug for Slice<K, V>

Source§

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

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

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

Source§

fn default() -> Self

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

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

Source§

fn default() -> Self

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

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

Source§

fn default() -> Self

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

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

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

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

Source§

type Output = Slice<K, V>

The returned type after indexing.
Source§

fn index(&self, range: (Bound<usize>, Bound<usize>)) -> &Self

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

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

Source§

type Output = Slice<K, V>

The returned type after indexing.
Source§

fn index(&self, range: Range<usize>) -> &Self

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

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

Source§

type Output = Slice<K, V>

The returned type after indexing.
Source§

fn index(&self, range: RangeFrom<usize>) -> &Self

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

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

Source§

type Output = Slice<K, V>

The returned type after indexing.
Source§

fn index(&self, range: RangeFull) -> &Self

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

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

Source§

type Output = Slice<K, V>

The returned type after indexing.
Source§

fn index(&self, range: RangeInclusive<usize>) -> &Self

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

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

Source§

type Output = Slice<K, V>

The returned type after indexing.
Source§

fn index(&self, range: RangeTo<usize>) -> &Self

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

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

Source§

type Output = Slice<K, V>

The returned type after indexing.
Source§

fn index(&self, range: RangeToInclusive<usize>) -> &Self

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

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

Source§

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 Self

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 Self

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 Self

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 Self

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 Self

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 Self

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 Self

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>

Source§

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

Which kind of iterator are we turning this into?
Source§

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

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

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

Which kind of iterator are we turning this into?
Source§

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

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

fn cmp(&self, other: &Self) -> Ordering

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

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

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

fn partial_cmp(&self, other: &Self) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

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

Auto Trait Implementations§

§

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

§

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> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

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

Source§

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

Checks if this value is equivalent to the given key. 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.

Layout§

Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.