Trait hacspec_lib::prelude::Index

1.0.0 · source · []
pub trait Index<Idx> where
    Idx: ?Sized
{ type Output: ?Sized; 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

The returned type after indexing.

Required Methods

Performs the indexing (container[index]) operation.

Panics

May panic if the index is out of bounds.

Implementors

impl Index<usize> for State

impl Index<u8> for State

impl Index<u32> for State

impl Index<i32> for State

impl Index<u8> for Constants

impl Index<u32> for Constants

impl Index<i32> for Constants

impl Index<usize> for Block

impl Index<u8> for Block

impl Index<u32> for Block

impl Index<i32> for Block

impl Index<usize> for ChaChaIV

impl Index<u8> for ChaChaIV

impl Index<u32> for ChaChaIV

impl Index<i32> for ChaChaIV

impl Index<u8> for ChaChaKey

impl Index<u32> for ChaChaKey

impl Index<i32> for ChaChaKey

impl Index<usize> for PolyKey

impl Index<u8> for PolyKey

impl Index<u32> for PolyKey

impl Index<i32> for PolyKey

impl Index<u8> for PolyBlock

impl Index<u32> for PolyBlock

impl Index<i32> for PolyBlock

impl Index<u8> for Poly1305Tag

impl Index<usize> for State

impl Index<u8> for State

impl Index<u32> for State

impl Index<i32> for State

impl Index<usize> for Row

impl Index<u8> for Row

impl Index<u32> for Row

impl Index<i32> for Row

impl Index<RangeFull> for Row

impl Index<u8> for Digest224

impl Index<u32> for Digest224

impl Index<i32> for Digest224

impl Index<u8> for Digest256

impl Index<u32> for Digest256

impl Index<i32> for Digest256

impl Index<u8> for Digest384

impl Index<u32> for Digest384

impl Index<i32> for Digest384

impl Index<u8> for Digest512

impl Index<u32> for Digest512

impl Index<i32> for Digest512

impl<'a, Q> Index<&'a Q> for Map<String, Value> where
    String: Borrow<Q>,
    Q: ?Sized + Ord + Eq + Hash

impl<I> Index<I> for Value where
    I: Index

impl<T, P> Index<usize> for Punctuated<T, P>

impl Index<usize> for Block

impl Index<u8> for Block

impl Index<u32> for Block

impl Index<i32> for Block

impl Index<usize> for Word

impl Index<u8> for Word

impl Index<u32> for Word

impl Index<i32> for Word

impl Index<RangeFull> for Word

impl Index<usize> for RoundKey

impl Index<u8> for RoundKey

impl Index<u32> for RoundKey

impl Index<i32> for RoundKey

impl Index<usize> for Nonce

impl Index<u8> for Nonce

impl Index<u32> for Nonce

impl Index<i32> for Nonce

impl Index<usize> for SBox

impl Index<u8> for SBox

impl Index<u32> for SBox

impl Index<i32> for SBox

impl Index<RangeFull> for SBox

impl Index<usize> for RCon

impl Index<u8> for RCon

impl Index<u32> for RCon

impl Index<i32> for RCon

impl Index<RangeFull> for RCon

impl Index<usize> for Bytes144

impl Index<u8> for Bytes144

impl Index<u32> for Bytes144

impl Index<i32> for Bytes144

impl Index<usize> for Bytes176

impl Index<u8> for Bytes176

impl Index<u32> for Bytes176

impl Index<i32> for Bytes176

impl Index<usize> for Bytes208

impl Index<u8> for Bytes208

impl Index<u32> for Bytes208

impl Index<i32> for Bytes208

impl Index<usize> for Bytes240

impl Index<u8> for Bytes240

impl Index<u32> for Bytes240

impl Index<i32> for Bytes240

impl Index<usize> for Key128

impl Index<u8> for Key128

impl Index<u32> for Key128

impl Index<i32> for Key128

impl Index<usize> for Key256

impl Index<u8> for Key256

impl Index<u32> for Key256

impl Index<i32> for Key256

impl Index<usize> for Block

impl Index<u8> for Block

impl Index<u32> for Block

impl Index<i32> for Block

impl Index<usize> for Key

impl Index<u8> for Key

impl Index<u32> for Key

impl Index<i32> for Key

impl Index<RangeFull> for Key

impl Index<usize> for Tag

impl Index<u8> for Tag

impl Index<u32> for Tag

impl Index<i32> for Tag

impl Index<RangeFull> for Tag

impl Index<usize> for DigestB

impl Index<u8> for DigestB

impl Index<u32> for DigestB

impl Index<i32> for DigestB

impl Index<usize> for Sigma

impl Index<u8> for Sigma

impl Index<u32> for Sigma

impl Index<i32> for Sigma

impl<T: Numeric + Copy> Index<usize> for State<T>

impl<T: Numeric + Copy> Index<u8> for State<T>

impl<T: Numeric + Copy> Index<u32> for State<T>

impl<T: Numeric + Copy> Index<i32> for State<T>

impl<T: Numeric + Copy> Index<RangeFull> for State<T>

impl<T: Numeric + Copy> Index<usize> for DoubleState<T>

impl<T: Numeric + Copy> Index<u8> for DoubleState<T>

impl<T: Numeric + Copy> Index<u32> for DoubleState<T>

impl<T: Numeric + Copy> Index<i32> for DoubleState<T>

impl<T: Numeric + Copy> Index<RangeFull> for DoubleState<T>

impl<T: Numeric + Copy> Index<usize> for Counter<T>

impl<T: Numeric + Copy> Index<u8> for Counter<T>

impl<T: Numeric + Copy> Index<u32> for Counter<T>

impl<T: Numeric + Copy> Index<i32> for Counter<T>

impl<T: Numeric + Copy> Index<RangeFull> for Counter<T>

impl Index<usize> for Block

impl Index<u8> for Block

impl Index<u32> for Block

impl Index<i32> for Block

impl Index<u8> for OpTableType

impl Index<usize> for Digest

impl Index<u8> for Digest

impl Index<u32> for Digest

impl Index<i32> for Digest

impl Index<usize> for Hash

impl Index<u8> for Hash

impl Index<u32> for Hash

impl Index<i32> for Hash

impl Index<RangeFull> for Hash