From c0327e98e0773c245a2af592769047cec316f34f Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Mon, 9 Dec 2024 21:38:58 +0000 Subject: [PATCH] Run cargo fmt --- osm2streets-py/src/lib.rs | 29 +++++++++-------------------- streets_reader/src/lib.rs | 14 +++++++++----- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/osm2streets-py/src/lib.rs b/osm2streets-py/src/lib.rs index d7a687f2..2e5098ee 100644 --- a/osm2streets-py/src/lib.rs +++ b/osm2streets-py/src/lib.rs @@ -49,8 +49,8 @@ impl PyStreetNetwork { ) -> PyResult { SETUP_LOGGER.call_once(|| env_logger::init()); - let input: ImportOptions = - serde_json::from_str(input.extract::<&str>(py)?).map_err(|e| err_to_py_value(format!("Failed to parse input: {}", e)))?; + let input: ImportOptions = serde_json::from_str(input.extract::<&str>(py)?) + .map_err(|e| err_to_py_value(format!("Failed to parse input: {}", e)))?; // Parse clip points if provided let clip_pts = if clip_pts_geojson.is_empty() { @@ -230,10 +230,7 @@ impl PyStreetNetwork { if let Some(ref way) = self.ways.get(&osm::WayID(id)) { Ok(serde_json::to_string_pretty(&way.tags).unwrap()) } else { - Err(err_to_py_value(format!( - "unknown way {}", - id - ))) + Err(err_to_py_value(format!("unknown way {}", id))) } } @@ -241,8 +238,7 @@ impl PyStreetNetwork { /// /// Returns a JSON string representing the full `StreetNetwork` data structure. pub fn to_json(&self) -> PyResult { - serde_json::to_string_pretty(&self.inner) - .map_err(err_to_py_runtime) + serde_json::to_string_pretty(&self.inner).map_err(err_to_py_runtime) } /// Retrieves the geometry of a way (road or path) as a buffered polygon in GeoJSON format. @@ -293,10 +289,7 @@ impl PyStreetNetwork { /// Returns an XML string for the way, or an error if the way does not exist. pub fn way_to_xml(&self, id: i64) -> PyResult { let Some(ref way) = self.ways.get(&osm::WayID(id)) else { - return Err(err_to_py_value(format!( - "unknown way {}", - id - ))); + return Err(err_to_py_value(format!("unknown way {}", id))); }; let mut out = format!(r#" PyResult<()> { let id = osm::WayID(id); - let tags: Tags = serde_json::from_str(tags).map_err(|e| err_to_py_value(format!("Failed to parse tags: {}", e)) - )?; + let tags: Tags = serde_json::from_str(tags) + .map_err(|e| err_to_py_value(format!("Failed to parse tags: {}", e)))?; let mut intersections = BTreeSet::new(); for road in self.inner.roads.values_mut() { @@ -382,10 +375,7 @@ impl PyStreetNetwork { if let Some(way) = self.ways.get_mut(&id) { way.tags = tags; } else { - return Err(err_to_py_value(format!( - "Unknown way ID {}", - id - ))); + return Err(err_to_py_value(format!("Unknown way ID {}", id))); } Ok(()) } @@ -458,9 +448,8 @@ fn err_to_py_runtime(err: E) -> PyErr { pyo3::exceptions::PyRuntimeError::new_err(err.to_string()) } - /// Converts any error implementing `std::fmt::Display` into a `PyValueError`. /// Used for invalid inputs or incorrect arguments passed by the user. fn err_to_py_value(err: E) -> PyErr { pyo3::exceptions::PyValueError::new_err(err.to_string()) -} \ No newline at end of file +} diff --git a/streets_reader/src/lib.rs b/streets_reader/src/lib.rs index 1826cb5a..477d1939 100644 --- a/streets_reader/src/lib.rs +++ b/streets_reader/src/lib.rs @@ -61,7 +61,10 @@ pub fn detect_country_code(streets: &mut StreetNetwork) { let codes = geocoder.ids(country_boundaries::LatLon::new(pt.y(), pt.x()).unwrap()); // Use the most specific country code for which we know a driving side. - let Some((code, side)) = codes.into_iter().find_map(|code| driving_side(code).map(|s| (code, s))) else { + let Some((code, side)) = codes + .into_iter() + .find_map(|code| driving_side(code).map(|s| (code, s))) + else { error!("detect_country_code failed -- {:?} didn't match to any country. Driving side may be wrong!", pt); return; }; @@ -85,10 +88,11 @@ fn extract_osm( timer, )?; // If GPSBounds aren't provided, they'll be computed in the Document - // LB 241209 - Added proper error handling due to processing errors, so it doesn't stop processing. - streets.gps_bounds = doc.gps_bounds.clone().ok_or_else(|| { - anyhow::anyhow!("Failed to extract GPS bounds from the OSM input") - })?; + // LB 241209 - Added proper error handling due to processing errors, so it doesn't stop processing. + streets.gps_bounds = doc + .gps_bounds + .clone() + .ok_or_else(|| anyhow::anyhow!("Failed to extract GPS bounds from the OSM input"))?; if let Some(pts) = clip_pts { streets.boundary_polygon =