Getty Ritter 1 year ago
parent
commit
3627a3c0e0
8 changed files with 23 additions and 16 deletions
  1. 2 2
      carpet/src/board.rs
  2. 6 0
      carpet/src/lib.rs
  3. 4 3
      carpet/src/vis.rs
  4. 3 3
      ch2/src/main.rs
  5. 2 2
      ch3/src/main.rs
  6. 2 2
      ch4/src/main.rs
  7. 3 3
      ch5/src/main.rs
  8. 1 1
      ch5/src/map.rs

+ 2 - 2
carpet/src/board.rs

@@ -239,7 +239,7 @@ impl<'a, T> Iterator for BoardWindowIter<'a, T> {
     type Item = (usize, usize, &'a T);
 
     fn next(&mut self) -> Option<Self::Item> {
-        while let Some(v) = self.iter.next() {
+        for v in self.iter.by_ref() {
             let x = self.n % self.width;
             let y = self.n / self.width;
             self.n += 1;
@@ -262,7 +262,7 @@ impl<'a, T> Iterator for BoardWindowIterMut<'a, T> {
     type Item = (usize, usize, &'a mut T);
 
     fn next(&mut self) -> Option<Self::Item> {
-        while let Some(v) = self.iter.next() {
+        for v in self.iter.by_ref() {
             let x = self.n % self.width;
             let y = self.n / self.width;
             self.n += 1;

+ 6 - 0
carpet/src/lib.rs

@@ -358,6 +358,12 @@ pub struct GameBuilder<Idx: Tile> {
     idx: std::marker::PhantomData<Idx>,
 }
 
+impl<Idx: Tile + 'static> Default for GameBuilder<Idx> {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 impl<Idx: Tile + 'static> GameBuilder<Idx> {
     pub fn new() -> GameBuilder<Idx> {
         GameBuilder {

+ 4 - 3
carpet/src/vis.rs

@@ -157,7 +157,9 @@ pub struct Viewshed<T> {
 
 impl<T> Viewshed<T> {
     pub fn create(original: &Board<T>, blocking: fn(&T) -> bool) -> Viewshed<T> {
-        let vis = Board::new_from(original.width(), original.height(), |_, _| Visibility::Unseen);
+        let vis = Board::new_from(original.width(), original.height(), |_, _| {
+            Visibility::Unseen
+        });
         let blocking = Box::new(blocking);
         Viewshed { vis, blocking }
     }
@@ -219,7 +221,7 @@ impl<T> Viewshed<T> {
 
 #[cfg(test)]
 mod test {
-    use crate::{Board, Coord, Visibility, Viewshed};
+    use crate::{Board, Coord, Viewshed, Visibility};
 
     macro_rules! board_from_vec {
         ($w:expr, $h:expr; [$($vec:tt)*]) => {
@@ -325,7 +327,6 @@ mod test {
         ];
         assert_eq!(v.vis, exp);
 
-
         v.calculate_from(&b, Coord::new(4, 2));
         let exp: Board<Visibility> = board_from_vec![
             7,5;

+ 3 - 3
ch2/src/main.rs

@@ -148,8 +148,8 @@ fn main() -> Result<(), GameError> {
     });
 
     game.run_with_systems(|world| {
-        Draw.run_now(&world);
-        Leftward.run_now(&world);
-        Move.run_now(&world);
+        Draw.run_now(world);
+        Leftward.run_now(world);
+        Move.run_now(world);
     })
 }

+ 2 - 2
ch3/src/main.rs

@@ -168,7 +168,7 @@ fn main() -> Result<(), GameError> {
     });
 
     game.run_with_systems(|world| {
-        Draw.run_now(&world);
-        Move.run_now(&world);
+        Draw.run_now(world);
+        Move.run_now(world);
     })
 }

+ 2 - 2
ch4/src/main.rs

@@ -201,7 +201,7 @@ fn main() -> Result<(), GameError> {
     }
 
     game.run_with_systems(|world| {
-        Draw.run_now(&world);
-        Move.run_now(&world);
+        Draw.run_now(world);
+        Move.run_now(world);
     })
 }

+ 3 - 3
ch5/src/main.rs

@@ -37,7 +37,7 @@ fn main() -> Result<(), GameError> {
         .rooms
         .first()
         .map(|r| r.center())
-        .unwrap_or([40, 25].into());
+        .unwrap_or_else(|| [40, 25].into());
     game.insert(map);
 
     game.create_entity()
@@ -60,7 +60,7 @@ fn main() -> Result<(), GameError> {
     }
 
     game.run_with_systems(|world| {
-        systems::Draw.run_now(&world);
-        systems::Move.run_now(&world);
+        systems::Draw.run_now(world);
+        systems::Move.run_now(world);
     })
 }

+ 1 - 1
ch5/src/map.rs

@@ -64,7 +64,7 @@ impl Map {
         let iter = self
             .tiles
             .window_iter_mut(rect)
-            .expect(&format!("Rect {:?} of map bounds", rect));
+            .unwrap_or_else(|| panic!("Rect {:?} of map bounds", rect));
         for (_, _, t) in iter {
             *t = TileType::Floor;
         }