From d515ced9a01e22205d9ef5740f51d39b0f74590d Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sat, 11 Dec 2021 16:08:22 +0100 Subject: [PATCH] 2021: day09: fix neighbour iterator lifetime --- aoc2021/src/day09.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aoc2021/src/day09.rs b/aoc2021/src/day09.rs index 9d21357..8b0d09a 100644 --- a/aoc2021/src/day09.rs +++ b/aoc2021/src/day09.rs @@ -88,10 +88,8 @@ impl HeightMap { } self.filled_points.insert((x, y)); - let neighbours: Vec<_> = self.neighbours(x, y).collect(); - neighbours - .iter() - .map(|&(nx, ny)| self.fill_basin(nx, ny)) + self.neighbours(x, y) + .map(|(nx, ny)| self.fill_basin(nx, ny)) .sum::() + 1 } @@ -105,11 +103,13 @@ impl HeightMap { }) } - fn neighbours(&self, x: usize, y: usize) -> impl Iterator + '_ { + fn neighbours(&self, x: usize, y: usize) -> impl Iterator + 'static { + let width = self.width; + let height = self.height; Neighbour::ALL .iter() .copied() - .filter_map(move |neighbour| neighbour.apply(x, y, self.width, self.height)) + .filter_map(move |neighbour| neighbour.apply(x, y, width, height)) } fn risk_level(&self, x: usize, y: usize) -> u64 {