Open frewsxcv opened 1 year ago
Just sharing in case it's something we want to consider
diff --git a/geozero/src/feature_processor.rs b/geozero/src/feature_processor.rs index 2b8554a..6b4c8d2 100644 --- a/geozero/src/feature_processor.rs +++ b/geozero/src/feature_processor.rs @@ -4,7 +4,7 @@ use crate::property_processor::PropertyProcessor; /// Feature processing trait #[allow(unused_variables)] -pub trait FeatureProcessor: GeomProcessor + PropertyProcessor { +pub trait FeatureProcessor: GeomProcessor + PropertyProcessor + Sized { /// Begin of dataset processing fn dataset_begin(&mut self, name: Option<&str>) -> Result<()> { Ok(()) @@ -22,10 +22,16 @@ pub trait FeatureProcessor: GeomProcessor + PropertyProcessor { Ok(()) } /// Begin of feature property processing + fn write_properties(&mut self, inner: impl FnOnce(&mut Self) -> Result<()>) -> Result<()> { + Ok(()) + } + /// Begin of feature property processing + #[deprecated] fn properties_begin(&mut self) -> Result<()> { Ok(()) } /// End of feature property processing + #[deprecated] fn properties_end(&mut self) -> Result<()> { Ok(()) } diff --git a/geozero/src/geojson/geojson_reader.rs b/geozero/src/geojson/geojson_reader.rs index 9d107a4..29fc714 100644 --- a/geozero/src/geojson/geojson_reader.rs +++ b/geozero/src/geojson/geojson_reader.rs @@ -121,9 +121,9 @@ fn process_geojson_feature<P: FeatureProcessor>( if feature.geometry.is_some() || feature.properties.is_some() { processor.feature_begin(idx as u64)?; if let Some(ref properties) = feature.properties { - processor.properties_begin()?; - process_properties(properties, processor)?; - processor.properties_end()?; + processor.write_properties(|processor| { + process_properties(properties, processor) + })?; } if let Some(ref geometry) = feature.geometry { processor.geometry_begin()?; diff --git a/geozero/src/geojson/geojson_writer.rs b/geozero/src/geojson/geojson_writer.rs index ac7f371..97214b4 100644 --- a/geozero/src/geojson/geojson_writer.rs +++ b/geozero/src/geojson/geojson_writer.rs @@ -54,6 +54,12 @@ impl<W: Write> FeatureProcessor for GeoJsonWriter<'_, W> { self.out.write_all(b"}")?; Ok(()) } + fn write_properties(&mut self, inner: impl FnOnce(&mut Self) -> Result<()>) -> Result<()> { + self.out.write_all(br#", "properties": {"#)?; + inner(self)?; + self.out.write_all(b"}")?; + Ok(()) + } fn properties_begin(&mut self) -> Result<()> { self.out.write_all(br#", "properties": {"#)?; Ok(())
Just sharing in case it's something we want to consider