Struct typed_index_collection::Idx
source · pub struct Idx<T>(_, _);
Expand description
Typed index.
Trait Implementations§
source§impl<T> Index<Idx<T>> for Collection<T>
impl<T> Index<Idx<T>> for Collection<T>
source§impl<T> IndexMut<Idx<T>> for Collection<T>
impl<T> IndexMut<Idx<T>> for Collection<T>
source§fn index_mut(&mut self, idx: Idx<T>) -> &mut T
fn index_mut(&mut self, idx: Idx<T>) -> &mut T
Access a mutable reference on an entry of the Collection
from its
Idx
.
use typed_index_collection::Collection;
let mut c = Collection::new(vec![-2, -1, 0, 1, 2]);
let negatives_idxs = c
.iter()
.filter(|(_, &v)| v < 0)
.map(|(idx, _)| idx)
.collect::<Vec<_>>();
for idx in negatives_idxs {
*c.index_mut(idx) = 0;
}
assert_eq!(vec![0, 0, 0, 1, 2], c.take());
source§impl<T> Ord for Idx<T>
impl<T> Ord for Idx<T>
source§impl<T> PartialEq<Idx<T>> for Idx<T>
impl<T> PartialEq<Idx<T>> for Idx<T>
source§impl<T> PartialOrd<Idx<T>> for Idx<T>
impl<T> PartialOrd<Idx<T>> for Idx<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read more