From 443c5c00f110536503d5cfd40689248c8626f7a9 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 27 Jun 2024 15:41:22 -0700 Subject: [PATCH] clippy fixes --- src/conversion/from_geo_types.rs | 46 ++++++++++++++++---------------- src/conversion/to_geo_types.rs | 2 +- src/de.rs | 2 +- src/feature_collection.rs | 2 +- src/feature_iterator.rs | 1 + src/feature_writer.rs | 16 +++++------ tests/roundtrip.rs | 2 +- 7 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/conversion/from_geo_types.rs b/src/conversion/from_geo_types.rs index 88cd899..8e96d7c 100644 --- a/src/conversion/from_geo_types.rs +++ b/src/conversion/from_geo_types.rs @@ -356,9 +356,9 @@ mod tests { #[test] fn geo_triangle_conversion_test() { - let c1 = Coord { x: 0., y: 0. }; - let c2 = Coord { x: 10., y: 20. }; - let c3 = Coord { x: 20., y: -10. }; + let c1: Coord = Coord { x: 0., y: 0. }; + let c2: Coord = Coord { x: 10., y: 20. }; + let c3: Coord = Coord { x: 20., y: -10. }; let triangle = Triangle(c1, c2, c3); @@ -366,14 +366,14 @@ mod tests { // Geo-types Polygon construction introduces an extra vertex: let's check it! if let Value::Polygon(c) = geojson_polygon { - assert_almost_eq!(c1.x as f64, c[0][0][0], 1e-6); - assert_almost_eq!(c1.y as f64, c[0][0][1], 1e-6); - assert_almost_eq!(c2.x as f64, c[0][1][0], 1e-6); - assert_almost_eq!(c2.y as f64, c[0][1][1], 1e-6); - assert_almost_eq!(c3.x as f64, c[0][2][0], 1e-6); - assert_almost_eq!(c3.y as f64, c[0][2][1], 1e-6); - assert_almost_eq!(c1.x as f64, c[0][3][0], 1e-6); - assert_almost_eq!(c1.y as f64, c[0][3][1], 1e-6); + assert_almost_eq!(c1.x, c[0][0][0], 1e-6); + assert_almost_eq!(c1.y, c[0][0][1], 1e-6); + assert_almost_eq!(c2.x, c[0][1][0], 1e-6); + assert_almost_eq!(c2.y, c[0][1][1], 1e-6); + assert_almost_eq!(c3.x, c[0][2][0], 1e-6); + assert_almost_eq!(c3.y, c[0][2][1], 1e-6); + assert_almost_eq!(c1.x, c[0][3][0], 1e-6); + assert_almost_eq!(c1.y, c[0][3][1], 1e-6); } else { panic!("Not valid geometry {:?}", geojson_polygon); } @@ -381,8 +381,8 @@ mod tests { #[test] fn geo_rect_conversion_test() { - let c1 = Coord { x: 0., y: 0. }; - let c2 = Coord { x: 10., y: 20. }; + let c1: Coord = Coord { x: 0., y: 0. }; + let c2: Coord = Coord { x: 10., y: 20. }; let rect = Rect::new(c1, c2); @@ -390,16 +390,16 @@ mod tests { // Geo-types Polygon construction introduces an extra vertex: let's check it! if let Value::Polygon(c) = geojson_polygon { - assert_almost_eq!(c1.x as f64, c[0][0][0], 1e-6); - assert_almost_eq!(c1.y as f64, c[0][0][1], 1e-6); - assert_almost_eq!(c1.x as f64, c[0][1][0], 1e-6); - assert_almost_eq!(c2.y as f64, c[0][1][1], 1e-6); - assert_almost_eq!(c2.x as f64, c[0][2][0], 1e-6); - assert_almost_eq!(c2.y as f64, c[0][2][1], 1e-6); - assert_almost_eq!(c2.x as f64, c[0][3][0], 1e-6); - assert_almost_eq!(c1.y as f64, c[0][3][1], 1e-6); - assert_almost_eq!(c1.x as f64, c[0][4][0], 1e-6); - assert_almost_eq!(c1.y as f64, c[0][4][1], 1e-6); + assert_almost_eq!(c1.x, c[0][0][0], 1e-6); + assert_almost_eq!(c1.y, c[0][0][1], 1e-6); + assert_almost_eq!(c1.x, c[0][1][0], 1e-6); + assert_almost_eq!(c2.y, c[0][1][1], 1e-6); + assert_almost_eq!(c2.x, c[0][2][0], 1e-6); + assert_almost_eq!(c2.y, c[0][2][1], 1e-6); + assert_almost_eq!(c2.x, c[0][3][0], 1e-6); + assert_almost_eq!(c1.y, c[0][3][1], 1e-6); + assert_almost_eq!(c1.x, c[0][4][0], 1e-6); + assert_almost_eq!(c1.y, c[0][4][1], 1e-6); } else { panic!("Not valid geometry {:?}", geojson_polygon); } diff --git a/src/conversion/to_geo_types.rs b/src/conversion/to_geo_types.rs index 0838b7d..b57907e 100644 --- a/src/conversion/to_geo_types.rs +++ b/src/conversion/to_geo_types.rs @@ -356,7 +356,7 @@ where T: CoordFloat, { let exterior = polygon_type - .get(0) + .first() .map(|e| create_geo_line_string(e)) .unwrap_or_else(|| create_geo_line_string(&vec![])); diff --git a/src/de.rs b/src/de.rs index 816a1cc..29863fa 100644 --- a/src/de.rs +++ b/src/de.rs @@ -471,7 +471,7 @@ pub(crate) mod tests { assert_eq!(records.len(), 2); let first_age = { - let props = records.get(0).unwrap().properties.as_ref().unwrap(); + let props = records.first().unwrap().properties.as_ref().unwrap(); props.get("age").unwrap().as_i64().unwrap() }; assert_eq!(first_age, 123); diff --git a/src/feature_collection.rs b/src/feature_collection.rs index 71101b1..f43da49 100644 --- a/src/feature_collection.rs +++ b/src/feature_collection.rs @@ -227,7 +227,7 @@ impl FromIterator for FeatureCollection { } Some(fbox) if curr_len == 0 => { // First iteration: just copy values from fbox - *curr_bbox = fbox.clone(); + curr_bbox.clone_from(fbox); } Some(fbox) if curr_len != fbox.len() => { bbox = None; diff --git a/src/feature_iterator.rs b/src/feature_iterator.rs index 9155067..27729ee 100644 --- a/src/feature_iterator.rs +++ b/src/feature_iterator.rs @@ -40,6 +40,7 @@ pub struct FeatureIterator<'de, R, D = Feature> { lifetime: PhantomData<&'de ()>, } +#[allow(clippy::enum_variant_names)] #[derive(Debug, Copy, Clone)] enum State { BeforeFeatures, diff --git a/src/feature_writer.rs b/src/feature_writer.rs index ad429f9..9ed00d0 100644 --- a/src/feature_writer.rs +++ b/src/feature_writer.rs @@ -187,11 +187,9 @@ impl FeatureWriter { value: &T, ) -> Result<()> { match self.state { - State::Finished => { - return Err(Error::InvalidWriterState( - "cannot write foreign member when writer has already finished", - )) - } + State::Finished => Err(Error::InvalidWriterState( + "cannot write foreign member when writer has already finished", + )), State::New => { self.write_str(r#"{ "type": "FeatureCollection", "#)?; write!(self.writer, "\"{key}\": ")?; @@ -201,11 +199,9 @@ impl FeatureWriter { self.state = State::WritingForeignMembers; Ok(()) } - State::WritingFeatures => { - return Err(Error::InvalidWriterState( - "must write foreign members before any features", - )) - } + State::WritingFeatures => Err(Error::InvalidWriterState( + "must write foreign members before any features", + )), State::WritingForeignMembers => { write!(self.writer, "\"{key}\": ")?; serde_json::to_writer(&mut self.writer, value)?; diff --git a/tests/roundtrip.rs b/tests/roundtrip.rs index 623d36d..db23d4b 100644 --- a/tests/roundtrip.rs +++ b/tests/roundtrip.rs @@ -47,7 +47,7 @@ mod roundtrip_tests { /// Verifies that we can parse and then re-encode geojson back to the same representation /// without losing any data. fn test_round_trip(file_path: &str) { - let mut file = File::open(&file_path).unwrap(); + let mut file = File::open(file_path).unwrap(); let mut file_contents = String::new(); let _ = file.read_to_string(&mut file_contents);