From eab0a498ee9601946414843beecc3815c50ee4b6 Mon Sep 17 00:00:00 2001 From: inthar-raven Date: Mon, 22 Apr 2024 13:41:15 -0400 Subject: [PATCH 1/2] Replace .iter().copied() on arrays with newer idiom .into_iter() --- common/src/node.rs | 2 +- server/src/sim.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/node.rs b/common/src/node.rs index 9a716665..a6e31dca 100644 --- a/common/src/node.rs +++ b/common/src/node.rs @@ -465,7 +465,7 @@ pub struct CoordAxisOutOfBounds; impl CoordAxis { /// Iterates through the the axes in ascending order pub fn iter() -> impl ExactSizeIterator { - [Self::X, Self::Y, Self::Z].iter().copied() + [Self::X, Self::Y, Self::Z].into_iter() } /// Returns the pair axes orthogonal to the current axis diff --git a/server/src/sim.rs b/server/src/sim.rs index 13ef1d03..8d2555eb 100644 --- a/server/src/sim.rs +++ b/server/src/sim.rs @@ -283,9 +283,9 @@ impl Sim { populate_fresh_nodes(&mut self.graph); let mut fresh_voxel_data = vec![]; - for fresh_node in fresh_nodes.iter().copied() { + for fresh_node in (&fresh_nodes).into_iter() { for vertex in Vertex::iter() { - let chunk = ChunkId::new(fresh_node, vertex); + let chunk = ChunkId::new(*fresh_node, vertex); if let Some(voxel_data) = self.preloaded_voxel_data.remove(&chunk) { fresh_voxel_data.push((chunk, voxel_data.serialize(self.cfg.chunk_size))); self.modified_chunks.insert(chunk); From 94a942b3610a70256a2ed312a35f212b521b3ffd Mon Sep 17 00:00:00 2001 From: inthar-raven Date: Mon, 22 Apr 2024 16:07:03 -0400 Subject: [PATCH 2/2] I think I need to keep .cloned() in some places since the values are used later. --- common/src/cursor.rs | 2 +- common/src/dodeca.rs | 2 +- common/src/graph.rs | 4 ++-- common/src/worldgen.rs | 2 +- server/src/sim.rs | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/common/src/cursor.rs b/common/src/cursor.rs index 61390752..1f31ac51 100644 --- a/common/src/cursor.rs +++ b/common/src/cursor.rs @@ -70,7 +70,7 @@ pub enum Dir { impl Dir { pub fn iter() -> impl ExactSizeIterator + Clone { use Dir::*; - [Left, Right, Down, Up, Forward, Back].iter().cloned() + [Left, Right, Down, Up, Forward, Back].into_iter() } /// Returns the unit vector corresponding to the direction. diff --git a/common/src/dodeca.rs b/common/src/dodeca.rs index efc4c234..0fc67201 100644 --- a/common/src/dodeca.rs +++ b/common/src/dodeca.rs @@ -32,7 +32,7 @@ impl Side { pub fn iter() -> impl ExactSizeIterator { use Side::*; - [A, B, C, D, E, F, G, H, I, J, K, L].iter().cloned() + [A, B, C, D, E, F, G, H, I, J, K, L].into_iter() } /// Whether `self` and `other` share an edge diff --git a/common/src/graph.rs b/common/src/graph.rs index df64e70f..7fcc628d 100644 --- a/common/src/graph.rs +++ b/common/src/graph.rs @@ -64,7 +64,7 @@ impl Graph { /// /// A node's length is defined as a its distance from the root node. pub fn canonicalize(&self, mut chunk: ChunkId) -> Option { - for side in chunk.vertex.canonical_sides().iter().cloned() { + for side in chunk.vertex.canonical_sides().into_iter() { // missing neighbors are always longer if let Some(neighbor) = self.neighbor(chunk.node, side) { if self.length(neighbor) < self.length(chunk.node) { @@ -392,7 +392,7 @@ mod tests { "both the root and some other node are common neighbors" ); assert!(common.contains(&NodeId::ROOT)); - let other = common.iter().cloned().find(|&x| x != NodeId::ROOT).unwrap(); + let other = common.into_iter().find(|&x| x != NodeId::ROOT).unwrap(); assert_eq!(graph.nodes[&other].length, 2); } diff --git a/common/src/worldgen.rs b/common/src/worldgen.rs index 8cd9fc26..15fe148a 100644 --- a/common/src/worldgen.rs +++ b/common/src/worldgen.rs @@ -693,7 +693,7 @@ mod test { let enviros = chunk_incident_enviro_factors(&g, ChunkId::new(NodeId::ROOT, Vertex::A)).unwrap(); - for (i, max_elevation) in enviros.max_elevations.iter().cloned().enumerate() { + for (i, max_elevation) in enviros.max_elevations.into_iter().enumerate() { println!("{i}, {max_elevation}"); assert_abs_diff_eq!(max_elevation, (i + 1) as f64, epsilon = 1e-8); } diff --git a/server/src/sim.rs b/server/src/sim.rs index 8d2555eb..3f4f3b99 100644 --- a/server/src/sim.rs +++ b/server/src/sim.rs @@ -283,9 +283,9 @@ impl Sim { populate_fresh_nodes(&mut self.graph); let mut fresh_voxel_data = vec![]; - for fresh_node in (&fresh_nodes).into_iter() { + for fresh_node in fresh_nodes.iter().cloned() { for vertex in Vertex::iter() { - let chunk = ChunkId::new(*fresh_node, vertex); + let chunk = ChunkId::new(fresh_node, vertex); if let Some(voxel_data) = self.preloaded_voxel_data.remove(&chunk) { fresh_voxel_data.push((chunk, voxel_data.serialize(self.cfg.chunk_size))); self.modified_chunks.insert(chunk);