fn check_adjs<P>(&self, idx: usize, f: P) -> bool
  where
    P: Fn(u8, u8) -> bool,
  {
    let row0 = idx - 1 - (self.cols as usize + 2);
    let row1 = idx - 1;
    let row2 = idx - 1 + (self.cols as usize + 2);
    let adj_idxs = [
      row0,
      row0 + 1,
      row0 + 2,
      row1,
      row1 + 2,
      row2,
      row2 + 1,
      row2 + 2,
    ];
    // For a 10 × 10 input, the adj indices of 0 × 0 cell would be
    // | 0   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 ...
    let (mut trees, mut lumberyard) = (0, 0);
    adj_idxs.iter().for_each(|&i| match self.data[i] {
      b'|' => trees += 1,
      b'#' => lumberyard += 1,
      _ => (),
    });
    f(trees, lumberyard)
  }
/** Iterates over adjacent cells and shortcircuits if f returns true */
Iterates over adjacent cells and shortcircuits if f returns true
Iterates over adjacent cells and shortcircuits if f returns true
fn check_adjs<P>(&self, idx: usize, f: P) -> bool
  where
    P: Fn(u8, u8) -> bool,
  {
    let row0 = idx - 1 - (self.cols as usize + 2);
    let row1 = idx - 1;
    let row2 = idx - 1 + (self.cols as usize + 2);
    let adj_idxs = [
      row0,
      row0 + 1,
      row0 + 2,
      row1,
      row1 + 2,
      row2,
      row2 + 1,
      row2 + 2,
    ];
    // For a 10 × 10 input, the adj indices of 0 × 0 cell would be
    // | 0   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 ...
    let (mut trees, mut lumberyard) = (0, 0);
    adj_idxs.iter().for_each(|&i| match self.data[i] {
      b'|' => trees += 1,
      b'#' => lumberyard += 1,
      _ => (),
    });
    f(trees, lumberyard)
  }
fn check_adjs < P > ( & self , idx : usize , f : P ) -> bool where P : Fn ( u8 , u8 ) -> bool , { let row0 = idx - 1 - ( self . cols as usize + 2 ) ; let row1 = idx - 1 ; let row2 = idx - 1 + ( self . cols as usize + 2 ) ; let adj_idxs = [ row0 , row0 + 1 , row0 + 2 , row1 , row1 + 2 , row2 , row2 + 1 , row2 + 2 , ] ; // For a 10 × 10 input, the adj indices of 0 × 0 cell would be // | 0   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 ... let ( mut trees , mut lumberyard ) = ( 0 , 0 ) ; adj_idxs . iter ( ) . for_each ( | & i | match self . data [ i ] { b'|' => trees += 1 , b'#' => lumberyard += 1 , _ => ( ) , } ) ; f ( trees , lumberyard ) }
Iterates over adjacent cells and shortcircuits if f returns true
Iterates over adjacent cells and shortcircuits if f returns true
&self
idx
usize
f
P