@@ -8,7 +8,13 @@ pub struct HashWorld {
8
8
pub cells : HashMap < ( int , int ) , State >
9
9
}
10
10
11
+ /*struct HashWorldIter {
12
+ iter: hash_map::Entries<(int, int), State + 'static>
13
+ }*/
14
+
11
15
pub trait World {
16
+ type WorldIter : Iterator < ( ( int , int ) , State ) > ;
17
+
12
18
fn get_cell ( & self , x : int , y : int ) -> State ;
13
19
14
20
fn set_cell ( & mut self , x : int , y : int ) ;
@@ -34,16 +40,30 @@ pub trait World {
34
40
///This will stay in this format for the forseeable future.
35
41
///Returning a generic iterator adds too much overhead to the
36
42
///iter() function
37
- fn iter ( & self ) -> hash_map:: Entries < ( int , int ) , State > ;
43
+ fn iter ( & self ) -> World :: WorldIter ;
44
+ }
45
+
46
+
47
+ /*impl HashWorldIter {
48
+ fn new(iter: hash_map::Entries<(int, int), State>) -> HashWorldIter {
49
+ HashWorldIter { iter: iter }
50
+ }
38
51
}
39
52
53
+ impl Iterator<((int, int), State)> for HashWorldIter {
54
+ fn next(&mut self) -> ((int, int), State) {
55
+ self.iter.next()
56
+ }
57
+ }*/
58
+
40
59
impl HashWorld {
41
60
pub fn new ( ) -> HashWorld {
42
61
HashWorld { cells : HashMap :: new ( ) }
43
62
}
44
63
}
45
64
46
65
impl World for HashWorld {
66
+ type WorldIter = hash_map:: Entries < ( int , int ) , State > ;
47
67
48
68
fn get_cell ( & self , x : int , y : int ) -> State {
49
69
match self . cells . get ( & ( x, y) ) {
0 commit comments