Trait Index

1.0.0 · Source
pub trait Index<Idx>
where Idx: ?Sized,
{ type Output: ?Sized; // Required method fn index(&self, index: Idx) -> &Self::Output; }
Expand description

core Used for indexing operations (container[index]) in immutable contexts.

Re-exported from core::ops:: .


Used for indexing operations (container[index]) in immutable contexts.

container[index] is actually syntactic sugar for *container.index(index), but only when used as an immutable value. If a mutable value is requested, IndexMut is used instead. This allows nice things such as let value = v[index] if the type of value implements Copy.

§Examples

The following example implements Index on a read-only NucleotideCount container, enabling individual counts to be retrieved with index syntax.

use std::ops::Index;

enum Nucleotide {
    A,
    C,
    G,
    T,
}

struct NucleotideCount {
    a: usize,
    c: usize,
    g: usize,
    t: usize,
}

impl Index<Nucleotide> for NucleotideCount {
    type Output = usize;

    fn index(&self, nucleotide: Nucleotide) -> &Self::Output {
        match nucleotide {
            Nucleotide::A => &self.a,
            Nucleotide::C => &self.c,
            Nucleotide::G => &self.g,
            Nucleotide::T => &self.t,
        }
    }
}

let nucleotide_count = NucleotideCount {a: 14, c: 9, g: 10, t: 12};
assert_eq!(nucleotide_count[Nucleotide::A], 14);
assert_eq!(nucleotide_count[Nucleotide::C], 9);
assert_eq!(nucleotide_count[Nucleotide::G], 10);
assert_eq!(nucleotide_count[Nucleotide::T], 12);

Required Associated Types§

1.0.0 · Source

type Output: ?Sized

The returned type after indexing.

Required Methods§

1.0.0 · Source

fn index(&self, index: Idx) -> &Self::Output

Performs the indexing (container[index]) operation.

§Panics

May panic if the index is out of bounds.

Implementors§

Source§

impl Index<usize> for ByteStr

Source§

impl Index<usize> for ByteString

§

impl Index<usize> for BStr

§

type Output = u8

§

impl Index<usize> for Bytes

§

type Output = u8

Source§

impl Index<usize> for Vec3A

Source§

impl Index<usize> for Vec4

Source§

impl Index<usize> for Vec2

Source§

impl Index<usize> for Vec3

Source§

impl Index<usize> for DVec2

Source§

impl Index<usize> for DVec3

Source§

impl Index<usize> for DVec4

Source§

impl Index<usize> for I8Vec2

Source§

impl Index<usize> for I8Vec3

Source§

impl Index<usize> for I8Vec4

Source§

impl Index<usize> for I16Vec2

Source§

impl Index<usize> for I16Vec3

Source§

impl Index<usize> for I16Vec4

Source§

impl Index<usize> for IVec2

Source§

impl Index<usize> for IVec3

Source§

impl Index<usize> for IVec4

Source§

impl Index<usize> for I64Vec2

Source§

impl Index<usize> for I64Vec3

Source§

impl Index<usize> for I64Vec4

Source§

impl Index<usize> for U8Vec2

Source§

impl Index<usize> for U8Vec3

Source§

impl Index<usize> for U8Vec4

Source§

impl Index<usize> for U16Vec2

Source§

impl Index<usize> for U16Vec3

Source§

impl Index<usize> for U16Vec4

Source§

impl Index<usize> for UVec2

Source§

impl Index<usize> for UVec3

Source§

impl Index<usize> for UVec4

Source§

impl Index<usize> for U64Vec2

Source§

impl Index<usize> for U64Vec3

Source§

impl Index<usize> for U64Vec4

§

impl Index<usize> for fiat_25519_loose_field_element

§

type Output = u32

§

impl Index<usize> for fiat_25519_loose_field_element

§

type Output = u64

§

impl Index<usize> for fiat_25519_scalar_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_25519_scalar_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_25519_scalar_non_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_25519_scalar_non_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_25519_tight_field_element

§

type Output = u32

§

impl Index<usize> for fiat_25519_tight_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p224_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p224_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p224_non_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p224_non_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p256_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p256_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p256_non_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p256_non_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p256_scalar_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p256_scalar_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p256_scalar_non_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p256_scalar_non_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p384_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p384_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p384_non_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p384_non_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p384_scalar_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p384_scalar_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p384_scalar_non_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p384_scalar_non_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p434_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p434_non_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p448_loose_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p448_loose_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p448_tight_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p448_tight_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p521_loose_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p521_loose_field_element

§

type Output = u64

§

impl Index<usize> for fiat_p521_tight_field_element

§

type Output = u32

§

impl Index<usize> for fiat_p521_tight_field_element

§

type Output = u64

§

impl Index<usize> for fiat_poly1305_loose_field_element

§

type Output = u32

§

impl Index<usize> for fiat_poly1305_loose_field_element

§

type Output = u64

§

impl Index<usize> for fiat_poly1305_tight_field_element

§

type Output = u32

§

impl Index<usize> for fiat_poly1305_tight_field_element

§

type Output = u64

§

impl Index<usize> for fiat_secp256k1_montgomery_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_secp256k1_montgomery_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_secp256k1_montgomery_non_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_secp256k1_montgomery_non_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_secp256k1_montgomery_scalar_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_secp256k1_montgomery_scalar_montgomery_domain_field_element

§

type Output = u64

§

impl Index<usize> for fiat_secp256k1_montgomery_scalar_non_montgomery_domain_field_element

§

type Output = u32

§

impl Index<usize> for fiat_secp256k1_montgomery_scalar_non_montgomery_domain_field_element

§

type Output = u64

§

impl Index<SpecialCodeIndex> for SpecialCodes

§

type Output = u8

Source§

impl Index<Range<usize>> for ByteStr

Source§

impl Index<Range<usize>> for ByteString

§

impl Index<Range<usize>> for BStr

§

type Output = BStr

§

impl Index<Range<usize>> for Bytes

§

impl Index<Range<usize>> for UninitSlice

§

type Output = UninitSlice

Source§

impl Index<RangeFrom<usize>> for ByteStr

Source§

impl Index<RangeFrom<usize>> for ByteString

§

impl Index<RangeFrom<usize>> for BStr

§

type Output = BStr

§

impl Index<RangeFrom<usize>> for Bytes

1.47.0 · Source§

impl Index<RangeFrom<usize>> for CStr

§

impl Index<RangeFrom<usize>> for UninitSlice

§

type Output = UninitSlice

Source§

impl Index<RangeFull> for ByteStr

Source§

impl Index<RangeFull> for ByteString

§

impl Index<RangeFull> for BStr

§

type Output = BStr

§

impl Index<RangeFull> for Bytes

1.7.0 · Source§

impl Index<RangeFull> for CString

1.0.0 · Source§

impl Index<RangeFull> for OsString

§

impl Index<RangeFull> for UninitSlice

§

type Output = UninitSlice

Source§

impl Index<RangeInclusive<usize>> for ByteStr

Source§

impl Index<RangeInclusive<usize>> for ByteString

§

impl Index<RangeInclusive<usize>> for BStr

§

type Output = BStr

§

impl Index<RangeInclusive<usize>> for Bytes

§

impl Index<RangeInclusive<usize>> for UninitSlice

§

type Output = UninitSlice

Source§

impl Index<RangeTo<usize>> for ByteStr

Source§

impl Index<RangeTo<usize>> for ByteString

§

impl Index<RangeTo<usize>> for BStr

§

type Output = BStr

§

impl Index<RangeTo<usize>> for Bytes

§

impl Index<RangeTo<usize>> for UninitSlice

§

type Output = UninitSlice

Source§

impl Index<RangeToInclusive<usize>> for ByteStr

Source§

impl Index<RangeToInclusive<usize>> for ByteString

§

impl Index<RangeToInclusive<usize>> for BStr

§

type Output = BStr

§

impl Index<RangeToInclusive<usize>> for Bytes

§

impl Index<RangeToInclusive<usize>> for UninitSlice

§

type Output = UninitSlice

§

impl<'a, K, V> Index<usize> for Keys<'a, K, V>

Access [IndexMap] keys at indexed positions.

While Index<usize> for IndexMap accesses a map’s values, indexing through [IndexMap::keys] offers an alternative to access a map’s keys instead.

Since Keys is also an iterator, consuming items from the iterator will offset the effective indexes. Similarly, if Keys is obtained from [Slice::keys], indexes will be interpreted relative to the position of that slice.

§Examples

use indexmap::IndexMap;

let mut map = IndexMap::new();
for word in "Lorem ipsum dolor sit amet".split_whitespace() {
    map.insert(word.to_lowercase(), word.to_uppercase());
}

assert_eq!(map[0], "LOREM");
assert_eq!(map.keys()[0], "lorem");
assert_eq!(map[1], "IPSUM");
assert_eq!(map.keys()[1], "ipsum");

map.reverse();
assert_eq!(map.keys()[0], "amet");
assert_eq!(map.keys()[1], "sit");

map.sort_keys();
assert_eq!(map.keys()[0], "amet");
assert_eq!(map.keys()[1], "dolor");

// Advancing the iterator will offset the indexing
let mut keys = map.keys();
assert_eq!(keys[0], "amet");
assert_eq!(keys.next().map(|s| &**s), Some("amet"));
assert_eq!(keys[0], "dolor");
assert_eq!(keys[1], "ipsum");

// Slices may have an offset as well
let slice = &map[2..];
assert_eq!(slice[0], "IPSUM");
assert_eq!(slice.keys()[0], "ipsum");
use indexmap::IndexMap;

let mut map = IndexMap::new();
map.insert("foo", 1);
println!("{:?}", map.keys()[10]); // panics!
§

type Output = K

§

impl<'a, T> Index<usize> for CSlice<'a, T>

§

type Output = T

§

impl<'a, T> Index<usize> for CSliceMut<'a, T>

§

type Output = T

§

impl<'a, V> Index<&'a usize> for VecMap<V>

§

type Output = V

§

impl<'bump> Index<Range<usize>> for devela::_dep::bumpalo::collections::String<'bump>

§

type Output = str

§

impl<'bump> Index<RangeFrom<usize>> for devela::_dep::bumpalo::collections::String<'bump>

§

type Output = str

§

impl<'bump> Index<RangeFull> for devela::_dep::bumpalo::collections::String<'bump>

§

type Output = str

§

impl<'bump> Index<RangeInclusive<usize>> for devela::_dep::bumpalo::collections::String<'bump>

§

type Output = str

§

impl<'bump> Index<RangeTo<usize>> for devela::_dep::bumpalo::collections::String<'bump>

§

type Output = str

§

impl<'bump> Index<RangeToInclusive<usize>> for devela::_dep::bumpalo::collections::String<'bump>

§

type Output = str

§

impl<'bump, T, I> Index<I> for devela::_dep::bumpalo::collections::Vec<'bump, T>
where I: SliceIndex<[T]>,

§

type Output = <I as SliceIndex<[T]>>::Output

§

impl<'h> Index<usize> for Captures<'h>

Get a matching capture group’s haystack substring by index.

The haystack substring returned can’t outlive the Captures object if this method is used, because of how Index is defined (normally a[i] is part of a and can’t outlive it). To work around this limitation, do that, use Captures::get instead.

'h is the lifetime of the matched haystack, but the lifetime of the &str returned by this implementation is the lifetime of the Captures value itself.

§Panics

If there is no matching group at the given index.

§

type Output = str

§

impl<'h, 'n> Index<&'n str> for Captures<'h>

Get a matching capture group’s haystack substring by name.

The haystack substring returned can’t outlive the Captures object if this method is used, because of how Index is defined (normally a[i] is part of a and can’t outlive it). To work around this limitation, do that, use Captures::get instead.

'h is the lifetime of the matched haystack, but the lifetime of the &str returned by this implementation is the lifetime of the Captures value itself.

'n is the lifetime of the group name used to index the Captures value.

§Panics

If there is no matching group at the given name.

§

type Output = str

§

impl<'s> Index<&'s str> for DocumentMut

§

type Output = Item

§

impl<'s> Index<&'s str> for InlineTable

§

impl<'s> Index<&'s str> for Table

§

type Output = Item

§

impl<A, I> Index<I> for SmallVec<A>
where A: Array, I: SliceIndex<[<A as Array>::Item]>,

§

type Output = <I as SliceIndex<[<A as Array>::Item]>>::Output

§

impl<Buffer> Index<(u8, u32, u32)> for FlatSamples<Buffer>
where Buffer: Index<usize>,

§

type Output = <Buffer as Index<usize>>::Output

§

impl<I> Index<I> for Item
where I: Index,

§

type Output = Item

1.0.0 · Source§

impl<I> Index<I> for str
where I: SliceIndex<str>,

§

impl<I> Index<I> for Bound<'_, PyBytes>
where I: SliceIndex<[u8]>,

This is the same way Vec is indexed.

§

type Output = <I as SliceIndex<[u8]>>::Output

1.0.0 · Source§

impl<I> Index<I> for devela::all::String
where I: SliceIndex<str>,

Source§

impl<I, T, const N: usize> Index<I> for Simd<T, N>

1.0.0 · Source§

impl<K, Q, V, A> Index<&Q> for BTreeMap<K, V, A>
where A: Allocator + Clone, K: Borrow<Q> + Ord, Q: Ord + ?Sized,

1.0.0 · Source§

impl<K, Q, V, S> Index<&Q> for devela::_dep::_std::collections::HashMap<K, V, S>
where K: Eq + Hash + Borrow<Q>, Q: Eq + Hash + ?Sized, S: BuildHasher,

§

impl<K, Q, V, S, A> Index<&Q> for devela::all::HashMap<K, V, S, A>
where K: Eq + Hash, Q: Hash + Equivalent<K> + ?Sized, S: BuildHasher, A: Allocator,

§

type Output = V

§

impl<K, T> Index<K> for HeaderMap<T>
where K: AsHeaderName,

§

type Output = T

§

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

§

type Output = Slice<K, V>

§

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

§

type Output = V

§

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

§

type Output = Slice<K, V>

§

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

§

type Output = Slice<K, V>

§

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

§

type Output = Slice<K, V>

§

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

§

type Output = Slice<K, V>

§

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

§

type Output = Slice<K, V>

§

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

§

type Output = Slice<K, V>

§

impl<K, V, Q, S> Index<&Q> for IndexMap<K, V, S>
where Q: Hash + Equivalent<K> + ?Sized, S: BuildHasher,

Access [IndexMap] values corresponding to a key.

§Examples

use indexmap::IndexMap;

let mut map = IndexMap::new();
for word in "Lorem ipsum dolor sit amet".split_whitespace() {
    map.insert(word.to_lowercase(), word.to_uppercase());
}
assert_eq!(map["lorem"], "LOREM");
assert_eq!(map["ipsum"], "IPSUM");
use indexmap::IndexMap;

let mut map = IndexMap::new();
map.insert("foo", 1);
println!("{:?}", map["bar"]); // panics!
§

type Output = V

§

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

§

type Output = Slice<K, V>

§

impl<K, V, S> Index<usize> for IndexMap<K, V, S>

Access [IndexMap] values at indexed positions.

See Index<usize> for Keys to access a map’s keys instead.

§Examples

use indexmap::IndexMap;

let mut map = IndexMap::new();
for word in "Lorem ipsum dolor sit amet".split_whitespace() {
    map.insert(word.to_lowercase(), word.to_uppercase());
}
assert_eq!(map[0], "LOREM");
assert_eq!(map[1], "IPSUM");
map.reverse();
assert_eq!(map[0], "AMET");
assert_eq!(map[1], "SIT");
map.sort_keys();
assert_eq!(map[0], "AMET");
assert_eq!(map[1], "DOLOR");
use indexmap::IndexMap;

let mut map = IndexMap::new();
map.insert("foo", 1);
println!("{:?}", map[10]); // panics!
§

type Output = V

§

impl<K, V, S> Index<Range<usize>> for IndexMap<K, V, S>

§

type Output = Slice<K, V>

§

impl<K, V, S> Index<RangeFrom<usize>> for IndexMap<K, V, S>

§

type Output = Slice<K, V>

§

impl<K, V, S> Index<RangeFull> for IndexMap<K, V, S>

§

type Output = Slice<K, V>

§

impl<K, V, S> Index<RangeInclusive<usize>> for IndexMap<K, V, S>

§

type Output = Slice<K, V>

§

impl<K, V, S> Index<RangeTo<usize>> for IndexMap<K, V, S>

§

type Output = Slice<K, V>

§

impl<K, V, S> Index<RangeToInclusive<usize>> for IndexMap<K, V, S>

§

type Output = Slice<K, V>

§

impl<P, Container> Index<(u32, u32)> for ImageBuffer<P, Container>
where P: Pixel, Container: Deref<Target = [<P as Pixel>::Subpixel]>,

§

type Output = P

§

impl<T> Index<(Bound<usize>, Bound<usize>)> for Slice<T>

§

type Output = Slice<T>

§

impl<T> Index<usize> for Luma<T>

§

type Output = T

§

impl<T> Index<usize> for LumaA<T>

§

type Output = T

§

impl<T> Index<usize> for Rgb<T>

§

type Output = T

§

impl<T> Index<usize> for Rgba<T>

§

type Output = T

§

impl<T> Index<usize> for CVec<T>

§

type Output = T

§

impl<T> Index<usize> for Slice<T>

§

type Output = T

§

impl<T> Index<Range<usize>> for Slice<T>

§

type Output = Slice<T>

§

impl<T> Index<RangeFrom<usize>> for Slice<T>

§

type Output = Slice<T>

§

impl<T> Index<RangeFull> for Slice<T>

§

type Output = Slice<T>

§

impl<T> Index<RangeInclusive<usize>> for Slice<T>

§

type Output = Slice<T>

§

impl<T> Index<RangeTo<usize>> for Slice<T>

§

type Output = Slice<T>

§

impl<T> Index<RangeToInclusive<usize>> for Slice<T>

§

type Output = Slice<T>

§

impl<T> Index<Key> for Arena<T>

§

type Output = T

1.0.0 · Source§

impl<T, A> Index<usize> for VecDeque<T, A>
where A: Allocator,

1.0.0 · Source§

impl<T, I> Index<I> for [T]
where I: SliceIndex<[T]>,

1.0.0 · Source§

impl<T, I, A> Index<I> for devela::all::Vec<T, A>
where I: SliceIndex<[T]>, A: Allocator,

1.50.0 · Source§

impl<T, I, const N: usize> Index<I> for [T; N]
where [T]: Index<I>,

Source§

type Output = <[T] as Index<I>>::Output

§

impl<T, S> Index<(Bound<usize>, Bound<usize>)> for IndexSet<T, S>

§

type Output = Slice<T>

§

impl<T, S> Index<usize> for IndexSet<T, S>

Access [IndexSet] values at indexed positions.

§Examples

use indexmap::IndexSet;

let mut set = IndexSet::new();
for word in "Lorem ipsum dolor sit amet".split_whitespace() {
    set.insert(word.to_string());
}
assert_eq!(set[0], "Lorem");
assert_eq!(set[1], "ipsum");
set.reverse();
assert_eq!(set[0], "amet");
assert_eq!(set[1], "sit");
set.sort();
assert_eq!(set[0], "Lorem");
assert_eq!(set[1], "amet");
use indexmap::IndexSet;

let mut set = IndexSet::new();
set.insert("foo");
println!("{:?}", set[10]); // panics!
§

type Output = T

§

impl<T, S> Index<Range<usize>> for IndexSet<T, S>

§

type Output = Slice<T>

§

impl<T, S> Index<RangeFrom<usize>> for IndexSet<T, S>

§

type Output = Slice<T>

§

impl<T, S> Index<RangeFull> for IndexSet<T, S>

§

type Output = Slice<T>

§

impl<T, S> Index<RangeInclusive<usize>> for IndexSet<T, S>

§

type Output = Slice<T>

§

impl<T, S> Index<RangeTo<usize>> for IndexSet<T, S>

§

type Output = Slice<T>

§

impl<T, S> Index<RangeToInclusive<usize>> for IndexSet<T, S>

§

type Output = Slice<T>

§

impl<V> Index<usize> for VecMap<V>

§

type Output = V