1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
//! A double-ended iterator over entity references and entities.
use crate::EntityRef;
use core::iter::Enumerate;
use core::marker::PhantomData;
use core::slice;
/// Iterate over all keys in order.
pub struct Iter<'a, K: EntityRef, V>
where
V: 'a,
{
enumerate: Enumerate<slice::Iter<'a, V>>,
unused: PhantomData<K>,
}
impl<'a, K: EntityRef, V> Iter<'a, K, V> {
/// Create an `Iter` iterator that visits the `PrimaryMap` keys and values
/// of `iter`.
pub fn new(iter: slice::Iter<'a, V>) -> Self {
Self {
enumerate: iter.enumerate(),
unused: PhantomData,
}
}
}
impl<'a, K: EntityRef, V> Iterator for Iter<'a, K, V> {
type Item = (K, &'a V);
fn next(&mut self) -> Option<Self::Item> {
self.enumerate.next().map(|(i, v)| (K::new(i), v))
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.enumerate.size_hint()
}
}
impl<'a, K: EntityRef, V> DoubleEndedIterator for Iter<'a, K, V> {
fn next_back(&mut self) -> Option<Self::Item> {
self.enumerate.next_back().map(|(i, v)| (K::new(i), v))
}
}
impl<'a, K: EntityRef, V> ExactSizeIterator for Iter<'a, K, V> {}
/// Iterate over all keys in order.
pub struct IterMut<'a, K: EntityRef, V>
where
V: 'a,
{
enumerate: Enumerate<slice::IterMut<'a, V>>,
unused: PhantomData<K>,
}
impl<'a, K: EntityRef, V> IterMut<'a, K, V> {
/// Create an `IterMut` iterator that visits the `PrimaryMap` keys and values
/// of `iter`.
pub fn new(iter: slice::IterMut<'a, V>) -> Self {
Self {
enumerate: iter.enumerate(),
unused: PhantomData,
}
}
}
impl<'a, K: EntityRef, V> Iterator for IterMut<'a, K, V> {
type Item = (K, &'a mut V);
fn next(&mut self) -> Option<Self::Item> {
self.enumerate.next().map(|(i, v)| (K::new(i), v))
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.enumerate.size_hint()
}
}
impl<'a, K: EntityRef, V> DoubleEndedIterator for IterMut<'a, K, V> {
fn next_back(&mut self) -> Option<Self::Item> {
self.enumerate.next_back().map(|(i, v)| (K::new(i), v))
}
}
impl<'a, K: EntityRef, V> ExactSizeIterator for IterMut<'a, K, V> {}
|