Movatterモバイル変換


[0]ホーム

URL:


Index

std::ops

TraitIndex 

1.0.0 (const:unstable) ·Source
pub trait Index<Idx>
where Idx: ?Sized,
{ typeOutput: ?Sized; // Required method fnindex(&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 aslet value = v[index] if the type ofvalue implementsCopy.

§Examples

The following example implementsIndex on a read-onlyNucleotideCountcontainer, enabling individual counts to be retrieved with index syntax.

usestd::ops::Index;enumNucleotide {    A,    C,    G,    T,}structNucleotideCount {    a: usize,    c: usize,    g: usize,    t: usize,}implIndex<Nucleotide>forNucleotideCount {typeOutput = usize;fnindex(&self, nucleotide: Nucleotide) ->&Self::Output {matchnucleotide {            Nucleotide::A =>&self.a,            Nucleotide::C =>&self.c,            Nucleotide::G =>&self.g,            Nucleotide::T =>&self.t,        }    }}letnucleotide_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

typeOutput: ?Sized

The returned type after indexing.

Required Methods§

1.0.0 ·Source

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

Performs the indexing (container[index]) operation.

§Panics

May panic if the index is out of bounds.

Implementors§

Source§

implIndex<usize> forByteString

Source§

implIndex<Range<usize>> forByteString

Source§

implIndex<RangeFrom<usize>> forByteString

1.47.0 ·Source§

implIndex<RangeFrom<usize>> forCStr

Source§

implIndex<RangeFull> forByteString

1.7.0 ·Source§

implIndex<RangeFull> forCString

1.0.0 ·Source§

implIndex<RangeFull> forOsString

Source§

implIndex<RangeInclusive<usize>> forByteString

Source§

implIndex<RangeTo<usize>> forByteString

Source§

implIndex<RangeToInclusive<usize>> forByteString

1.0.0 (const:unstable) ·Source§

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

Source§

impl<I>Index<I> forByteStr

1.0.0 ·Source§

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

Source§

impl<I, T, const N:usize>Index<I> forSimd<T, N>

1.0.0 ·Source§

impl<K, Q, V, A>Index<&Q> forBTreeMap<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> forHashMap<K, V, S>
where K:Eq +Hash +Borrow<Q>, Q:Eq +Hash + ?Sized, S:BuildHasher,

1.0.0 ·Source§

impl<T, A>Index<usize> forVecDeque<T, A>
where A:Allocator,

1.0.0 (const:unstable) ·Source§

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

1.0.0 ·Source§

impl<T, I, A>Index<I> forVec<T, A>
where I:SliceIndex<[T]>, A:Allocator,

1.50.0 (const:unstable) ·Source§

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


[8]ページ先頭

©2009-2026 Movatter.jp