Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkirk committed Jun 27, 2024
1 parent cd43330 commit 443c5c0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 37 deletions.
46 changes: 23 additions & 23 deletions src/conversion/from_geo_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,50 +356,50 @@ 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<f64> = Coord { x: 0., y: 0. };
let c2: Coord<f64> = Coord { x: 10., y: 20. };
let c3: Coord<f64> = Coord { x: 20., y: -10. };

let triangle = Triangle(c1, c2, c3);

let geojson_polygon = Value::from(&triangle);

// 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);
}
}

#[test]
fn geo_rect_conversion_test() {
let c1 = Coord { x: 0., y: 0. };
let c2 = Coord { x: 10., y: 20. };
let c1: Coord<f64> = Coord { x: 0., y: 0. };
let c2: Coord<f64> = Coord { x: 10., y: 20. };

let rect = Rect::new(c1, c2);

let geojson_polygon = Value::from(&rect);

// 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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/conversion/to_geo_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![]));

Expand Down
2 changes: 1 addition & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/feature_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl FromIterator<Feature> 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;
Expand Down
1 change: 1 addition & 0 deletions src/feature_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 6 additions & 10 deletions src/feature_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ impl<W: Write> FeatureWriter<W> {
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}\": ")?;
Expand All @@ -201,11 +199,9 @@ impl<W: Write> FeatureWriter<W> {
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)?;
Expand Down
2 changes: 1 addition & 1 deletion tests/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 443c5c0

Please sign in to comment.