devela::_core::ops

Trait Index

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

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§

§

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<SpecialCodeIndex> for SpecialCodes

§

type Output = u8

§

impl Index<Range<usize>> for ArchivedString

§

type Output = str

§

impl Index<Range<usize>> for BStr

§

type Output = BStr

§

impl Index<Range<usize>> for Bytes

§

impl Index<Range<usize>> for UninitSlice

§

type Output = UninitSlice

§

impl Index<RangeFrom<usize>> for ArchivedString

§

type Output = str

§

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

§

impl Index<RangeFull> for ArchivedCString

§

type Output = CStr

§

impl Index<RangeFull> for ArchivedString

§

type Output = str

§

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

§

impl Index<RangeInclusive<usize>> for ArchivedString

§

type Output = str

§

impl Index<RangeInclusive<usize>> for BStr

§

type Output = BStr

§

impl Index<RangeInclusive<usize>> for Bytes

§

impl Index<RangeInclusive<usize>> for UninitSlice

§

type Output = UninitSlice

§

impl Index<RangeTo<usize>> for ArchivedString

§

type Output = str

§

impl Index<RangeTo<usize>> for BStr

§

type Output = BStr

§

impl Index<RangeTo<usize>> for Bytes

§

impl Index<RangeTo<usize>> for UninitSlice

§

type Output = UninitSlice

§

impl Index<RangeToInclusive<usize>> for ArchivedString

§

type Output = str

§

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<'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<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

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,

§

impl<K, Q, V, H> Index<&Q> for ArchivedHashMap<K, V, H>
where K: Eq + Hash + Borrow<Q>, Q: Eq + Hash + ?Sized, H: Default + Hasher,

§

type Output = V

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, V, Q, const E: usize> Index<&Q> for ArchivedBTreeMap<K, V, E>
where Q: Ord + ?Sized, K: Borrow<Q> + Ord,

§

type Output = V

§

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]>,

§

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

§

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

§

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

§

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

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, I, const N: usize> Index<I> for InlineVec<T, N>
where I: SliceIndex<[T]>,

§

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

§

impl<const A: usize, I> Index<I> for AlignedVec<A>
where I: SliceIndex<[u8]>,

§

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