Skip to content

Commit c0327e9

Browse files
committed
Run cargo fmt
1 parent 2a7b669 commit c0327e9

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

osm2streets-py/src/lib.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ impl PyStreetNetwork {
4949
) -> PyResult<Self> {
5050
SETUP_LOGGER.call_once(|| env_logger::init());
5151

52-
let input: ImportOptions =
53-
serde_json::from_str(input.extract::<&str>(py)?).map_err(|e| err_to_py_value(format!("Failed to parse input: {}", e)))?;
52+
let input: ImportOptions = serde_json::from_str(input.extract::<&str>(py)?)
53+
.map_err(|e| err_to_py_value(format!("Failed to parse input: {}", e)))?;
5454

5555
// Parse clip points if provided
5656
let clip_pts = if clip_pts_geojson.is_empty() {
@@ -230,19 +230,15 @@ impl PyStreetNetwork {
230230
if let Some(ref way) = self.ways.get(&osm::WayID(id)) {
231231
Ok(serde_json::to_string_pretty(&way.tags).unwrap())
232232
} else {
233-
Err(err_to_py_value(format!(
234-
"unknown way {}",
235-
id
236-
)))
233+
Err(err_to_py_value(format!("unknown way {}", id)))
237234
}
238235
}
239236

240237
/// Converts the entire `StreetNetwork` to a JSON format.
241238
///
242239
/// Returns a JSON string representing the full `StreetNetwork` data structure.
243240
pub fn to_json(&self) -> PyResult<String> {
244-
serde_json::to_string_pretty(&self.inner)
245-
.map_err(err_to_py_runtime)
241+
serde_json::to_string_pretty(&self.inner).map_err(err_to_py_runtime)
246242
}
247243

248244
/// Retrieves the geometry of a way (road or path) as a buffered polygon in GeoJSON format.
@@ -293,10 +289,7 @@ impl PyStreetNetwork {
293289
/// Returns an XML string for the way, or an error if the way does not exist.
294290
pub fn way_to_xml(&self, id: i64) -> PyResult<String> {
295291
let Some(ref way) = self.ways.get(&osm::WayID(id)) else {
296-
return Err(err_to_py_value(format!(
297-
"unknown way {}",
298-
id
299-
)));
292+
return Err(err_to_py_value(format!("unknown way {}", id)));
300293
};
301294
let mut out = format!(r#"<way id="{}""#, id);
302295
if let Some(version) = way.version {
@@ -359,8 +352,8 @@ impl PyStreetNetwork {
359352
/// Updates the roads and intersections connected to this way based on the new tags.
360353
pub fn overwrite_osm_tags_for_way(&mut self, id: i64, tags: &str) -> PyResult<()> {
361354
let id = osm::WayID(id);
362-
let tags: Tags = serde_json::from_str(tags).map_err(|e| err_to_py_value(format!("Failed to parse tags: {}", e))
363-
)?;
355+
let tags: Tags = serde_json::from_str(tags)
356+
.map_err(|e| err_to_py_value(format!("Failed to parse tags: {}", e)))?;
364357

365358
let mut intersections = BTreeSet::new();
366359
for road in self.inner.roads.values_mut() {
@@ -382,10 +375,7 @@ impl PyStreetNetwork {
382375
if let Some(way) = self.ways.get_mut(&id) {
383376
way.tags = tags;
384377
} else {
385-
return Err(err_to_py_value(format!(
386-
"Unknown way ID {}",
387-
id
388-
)));
378+
return Err(err_to_py_value(format!("Unknown way ID {}", id)));
389379
}
390380
Ok(())
391381
}
@@ -458,9 +448,8 @@ fn err_to_py_runtime<E: std::fmt::Display>(err: E) -> PyErr {
458448
pyo3::exceptions::PyRuntimeError::new_err(err.to_string())
459449
}
460450

461-
462451
/// Converts any error implementing `std::fmt::Display` into a `PyValueError`.
463452
/// Used for invalid inputs or incorrect arguments passed by the user.
464453
fn err_to_py_value<E: std::fmt::Display>(err: E) -> PyErr {
465454
pyo3::exceptions::PyValueError::new_err(err.to_string())
466-
}
455+
}

streets_reader/src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ pub fn detect_country_code(streets: &mut StreetNetwork) {
6161
let codes = geocoder.ids(country_boundaries::LatLon::new(pt.y(), pt.x()).unwrap());
6262

6363
// Use the most specific country code for which we know a driving side.
64-
let Some((code, side)) = codes.into_iter().find_map(|code| driving_side(code).map(|s| (code, s))) else {
64+
let Some((code, side)) = codes
65+
.into_iter()
66+
.find_map(|code| driving_side(code).map(|s| (code, s)))
67+
else {
6568
error!("detect_country_code failed -- {:?} didn't match to any country. Driving side may be wrong!", pt);
6669
return;
6770
};
@@ -85,10 +88,11 @@ fn extract_osm(
8588
timer,
8689
)?;
8790
// If GPSBounds aren't provided, they'll be computed in the Document
88-
// LB 241209 - Added proper error handling due to processing errors, so it doesn't stop processing.
89-
streets.gps_bounds = doc.gps_bounds.clone().ok_or_else(|| {
90-
anyhow::anyhow!("Failed to extract GPS bounds from the OSM input")
91-
})?;
91+
// LB 241209 - Added proper error handling due to processing errors, so it doesn't stop processing.
92+
streets.gps_bounds = doc
93+
.gps_bounds
94+
.clone()
95+
.ok_or_else(|| anyhow::anyhow!("Failed to extract GPS bounds from the OSM input"))?;
9296

9397
if let Some(pts) = clip_pts {
9498
streets.boundary_polygon =

0 commit comments

Comments
 (0)