osm_io/osm/pbf/
parallel_element_iteration_command.rs1use std::sync::Arc;
2
3use anyhow::Error;
4use command_executor::command::Command;
5
6use crate::osm::model::element::Element;
7use crate::osm::pbf::blob_desc::BlobDesc;
8use crate::osm::pbf::file_block::FileBlock;
9
10pub(crate) struct ParallelElementIterationCommand {
11 blob_desc: BlobDesc,
12 f: Arc<dyn Fn(Element) -> Result<(), Error> + Send + Sync + 'static>,
13}
14
15impl ParallelElementIterationCommand {
16 pub(crate) fn new(blob_desc: BlobDesc, f: Arc<impl Fn(Element) -> Result<(), Error> + Send + Sync + 'static>) -> ParallelElementIterationCommand {
17 ParallelElementIterationCommand {
18 blob_desc,
19 f,
20 }
21 }
22}
23
24impl Command for ParallelElementIterationCommand {
25 fn execute(&self) -> Result<(), Error> {
26 let mut file_block = FileBlock::from_blob_desc(&self.blob_desc)?;
27 if file_block.is_osm_data() {
28 for element in file_block.take_elements() {
29 (self.f)(element)?;
30 }
31 (self.f)(Element::Sentinel)?;
32 }
33 Ok(())
34 }
35}