From 0d5624fe4c6ce19259d6cd7ce8407f14a8c2a083 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 14 Mar 2022 11:46:48 -0500 Subject: [PATCH] Bump edition and appease Clippy. --- Cargo.toml | 2 +- src/filter/bsp_interior.rs | 3 +-- src/filter/bsp_rooms.rs | 5 ++--- src/lib.rs | 2 +- src/map.rs | 13 +++++++------ src/random.rs | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 366c71d..d2eb52a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/klangner/mapgen.rs" homepage = "https://github.com/klangner/mapgen.rs" documentation = "https://docs.rs/mapgen" -edition = "2018" +edition = "2021" [dependencies] rand = "0.8" diff --git a/src/filter/bsp_interior.rs b/src/filter/bsp_interior.rs index 85eeb63..4968bc0 100644 --- a/src/filter/bsp_interior.rs +++ b/src/filter/bsp_interior.rs @@ -49,8 +49,7 @@ impl BspInterior { fn build(&self, rng: &mut StdRng, map: &Map) -> Map { let mut new_map = map.clone(); - let mut rects: Vec = Vec::new(); - rects.push(Rect::new(1, 1, new_map.width - 2, new_map.height - 2)); + let mut rects = vec![Rect::new(1, 1, new_map.width - 2, new_map.height - 2)]; let first_room = rects[0]; // Divide the first room self.add_subrects(first_room, rng, &mut rects); diff --git a/src/filter/bsp_rooms.rs b/src/filter/bsp_rooms.rs index cd73551..1ad479b 100644 --- a/src/filter/bsp_rooms.rs +++ b/src/filter/bsp_rooms.rs @@ -47,9 +47,8 @@ impl BspRooms { fn build_rooms(&self, map: &Map, rng: &mut StdRng) -> Map { let mut new_map = map.clone(); - let mut rects: Vec = Vec::new(); // Start with a single map-sized rectangle - rects.push(Rect::new(2, 2, new_map.width - 5, new_map.height - 5)); + let mut rects = vec![Rect::new(2, 2, new_map.width - 5, new_map.height - 5)]; let first_room = rects[0]; rects.append(&mut self.split_into_subrects(first_room)); // Divide the first room @@ -98,7 +97,7 @@ impl BspRooms { rects } - fn get_random_rect(&self, rng: &mut StdRng, rects: &Vec) -> Rect { + fn get_random_rect(&self, rng: &mut StdRng, rects: &[Rect]) -> Rect { if rects.len() == 1 { return rects[0]; } diff --git a/src/lib.rs b/src/lib.rs index c3c9bae..e530894 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,6 +114,6 @@ mod tests { assert_eq!(map.width, 80); assert_eq!(map.height, 50); - assert_eq!(map.starting_point.is_some(), true); + assert!(map.starting_point.is_some()); } } diff --git a/src/map.rs b/src/map.rs index 2f34fa5..72d4d74 100644 --- a/src/map.rs +++ b/src/map.rs @@ -84,11 +84,12 @@ impl Map { } /// Create map from given string + #[allow(clippy::needless_range_loop)] pub fn from_string(map_string: &str) -> Map { let lines: Vec<&str> = map_string - .split("\n") + .split('\n') .map(|l| l.trim()) - .filter(|l| l.len() > 0) + .filter(|l| !l.is_empty()) .collect(); let cols = lines .iter() @@ -157,7 +158,7 @@ impl Map { // Check if given tile can be accessed fn is_exit_valid(&self, x: usize, y: usize) -> bool { - self.at(x, y).is_blocked == false + !self.at(x, y).is_blocked } /// Modify tile at the given location @@ -276,7 +277,7 @@ impl fmt::Display for Map { .map(|x| if self.at(x, y).is_blocked { '#' } else { ' ' } as u8) .collect(); let line = String::from_utf8(bytes).expect("Can't convert map to string"); - let _ = write!(f, "{}\n", line); + let _ = writeln!(f, "{}", line); } Ok(()) } @@ -316,7 +317,7 @@ mod tests { if i == 0 || i == 9 { assert!(map.at(i, 1).is_blocked); } else { - assert!(map.at(i, 1).is_blocked == false); + assert!(map.at(i, 1).is_walkable()); } } } @@ -344,7 +345,7 @@ mod tests { if x == 0 || y == 0 || x == 4 || y == 4 { assert!(map.at(x, y).is_blocked); } else { - assert!(map.at(x, y).is_blocked == false); + assert!(map.at(x, y).is_walkable()); } } } diff --git a/src/random.rs b/src/random.rs index f1b57f8..620d426 100644 --- a/src/random.rs +++ b/src/random.rs @@ -36,7 +36,7 @@ mod tests { fn test_range() { let mut rng = StdRng::seed_from_u64(100); let x = rng.random_range(5, 8); - assert!(x >= 5 && x < 8); + assert!((5..8).contains(&x)); } #[test]