Trait ethcore_util::standard::ops::Index 1.0.0
[−]
[src]
pub trait Index<Idx> where Idx: ?Sized {
type Output: ?Sized;
fn index(&self, index: Idx) -> &Self::Output;
}
The Index
trait is used to specify the functionality of indexing operations
like container[index]
when used in an immutable context.
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 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) -> &usize { 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);
Associated Types
Required Methods
fn index(&self, index: Idx) -> &Self::Output
The method for the indexing (container[index]
) operation
Implementors
impl<'a, K, Q, V> Index<&'a Q> for BTreeMap<K, V> where K: Ord + Borrow<Q>, Q: Ord + ?Sized
impl Index<Range<usize>> for String
impl Index<RangeTo<usize>> for String
impl Index<RangeFrom<usize>> for String
impl Index<RangeFull> for String
impl Index<RangeInclusive<usize>> for String
impl Index<RangeToInclusive<usize>> for String
impl<T> Index<usize> for Vec<T>
impl<T> Index<Range<usize>> for Vec<T>
impl<T> Index<RangeTo<usize>> for Vec<T>
impl<T> Index<RangeFrom<usize>> for Vec<T>
impl<T> Index<RangeFull> for Vec<T>
impl<T> Index<RangeInclusive<usize>> for Vec<T>
impl<T> Index<RangeToInclusive<usize>> for Vec<T>
impl<A> Index<usize> for VecDeque<A>
impl Index<usize> for SharedSecret
impl Index<Range<usize>> for SharedSecret
impl Index<RangeFrom<usize>> for SharedSecret
impl Index<RangeFull> for SharedSecret
impl Index<usize> for Signature
impl Index<Range<usize>> for Signature
impl Index<RangeFrom<usize>> for Signature
impl Index<RangeFull> for Signature
impl Index<usize> for PublicKey
impl Index<Range<usize>> for PublicKey
impl Index<RangeTo<usize>> for PublicKey
impl Index<RangeFrom<usize>> for PublicKey
impl Index<RangeFull> for PublicKey
impl Index<usize> for Signature
impl Index<Range<usize>> for Signature
impl Index<RangeTo<usize>> for Signature
impl Index<RangeFrom<usize>> for Signature
impl Index<RangeFull> for Signature
impl Index<usize> for RecoverableSignature
impl Index<Range<usize>> for RecoverableSignature
impl Index<RangeTo<usize>> for RecoverableSignature
impl Index<RangeFrom<usize>> for RecoverableSignature
impl Index<RangeFull> for RecoverableSignature
impl Index<usize> for SharedSecret
impl Index<Range<usize>> for SharedSecret
impl Index<RangeTo<usize>> for SharedSecret
impl Index<RangeFrom<usize>> for SharedSecret
impl Index<RangeFull> for SharedSecret
impl Index<usize> for SecretKey
impl Index<Range<usize>> for SecretKey
impl Index<RangeTo<usize>> for SecretKey
impl Index<RangeFrom<usize>> for SecretKey
impl Index<RangeFull> for SecretKey
impl Index<usize> for Signature
impl Index<Range<usize>> for Signature
impl Index<RangeTo<usize>> for Signature
impl Index<RangeFrom<usize>> for Signature
impl Index<RangeFull> for Signature
impl Index<usize> for Message
impl Index<Range<usize>> for Message
impl Index<RangeTo<usize>> for Message
impl Index<RangeFrom<usize>> for Message
impl Index<RangeFull> for Message
impl<A> Index<usize> for SmallVec<A> where A: Array
impl<A> Index<Range<usize>> for SmallVec<A> where A: Array
impl<A> Index<RangeFrom<usize>> for SmallVec<A> where A: Array
impl<A> Index<RangeTo<usize>> for SmallVec<A> where A: Array
impl<A> Index<RangeFull> for SmallVec<A> where A: Array
impl Index<usize> for H32
impl Index<Range<usize>> for H32
impl Index<RangeFull> for H32
impl Index<usize> for H64
impl Index<Range<usize>> for H64
impl Index<RangeFull> for H64
impl Index<usize> for H128
impl Index<Range<usize>> for H128
impl Index<RangeFull> for H128
impl Index<usize> for H160
impl Index<Range<usize>> for H160
impl Index<RangeFull> for H160
impl Index<usize> for H256
impl Index<Range<usize>> for H256
impl Index<RangeFull> for H256
impl Index<usize> for H264
impl Index<Range<usize>> for H264
impl Index<RangeFull> for H264
impl Index<usize> for H512
impl Index<Range<usize>> for H512
impl Index<RangeFull> for H512
impl Index<usize> for H520
impl Index<Range<usize>> for H520
impl Index<RangeFull> for H520
impl Index<usize> for H1024
impl Index<Range<usize>> for H1024
impl Index<RangeFull> for H1024
impl Index<usize> for H2048
impl Index<Range<usize>> for H2048
impl Index<RangeFull> for H2048
impl<T> Index<usize> for [T]
impl<T> Index<Range<usize>> for [T]
impl<T> Index<RangeTo<usize>> for [T]
impl<T> Index<RangeFrom<usize>> for [T]
impl<T> Index<RangeFull> for [T]
impl<T> Index<RangeInclusive<usize>> for [T]
impl<T> Index<RangeToInclusive<usize>> for [T]
impl Index<Range<usize>> for str
impl Index<RangeTo<usize>> for str
impl Index<RangeFrom<usize>> for str
impl Index<RangeFull> for str
impl Index<RangeInclusive<usize>> for str
impl Index<RangeToInclusive<usize>> for str
impl<'a, K, Q, V, S> Index<&'a Q> for HashMap<K, V, S> where K: Eq + Hash + Borrow<Q>, Q: Eq + Hash + ?Sized, S: BuildHasher
impl Index<RangeFull> for CString
impl Index<RangeFull> for OsString
impl<'a, A> Index<usize> for Stride<'a, A>
impl<'a, A> Index<usize> for StrideMut<'a, A>
impl<'t> Index<usize> for Captures<'t>
impl<'t, 'i> Index<&'i str> for Captures<'t>
impl<'t> Index<usize> for Captures<'t>
impl<'t, 'i> Index<&'i str> for Captures<'t>
impl<'a, K, V, S, Q> Index<&'a Q> for LinkedHashMap<K, V, S> where K: Hash + Eq + Borrow<Q>, Q: Eq + Hash + ?Sized, S: BuildHasher
impl<'a> Index<&'a str> for Json
impl Index<usize> for Json