use rayon::prelude::*;
#[cfg(feature = "cli")]
use clap::ValueEnum;
use std::{path::PathBuf, sync::mpsc::Receiver};
use crate::{chunks::ElementChunk, elements::Metadata, SkywayError};
#[cfg(feature = "cli")]
use crate::FileFormatOptions;
#[cfg(feature = "json")]
mod json;
#[cfg(feature = "json")]
pub use json::JsonWriter;
#[cfg(feature = "o5m")]
mod o5m;
#[cfg(feature = "opl")]
mod opl;
#[cfg(feature = "opl")]
pub use opl::OplWriter;
#[cfg(feature = "xml")]
mod xml;
#[cfg(feature = "xml")]
pub use xml::XmlWriter;
#[cfg(feature = "cli")]
#[derive(Clone, Debug, ValueEnum)]
pub enum OutputFileFormat {
#[cfg(feature = "json")]
#[value(name = "json")]
Json,
#[cfg(feature = "opl")]
#[value(name = "opl")]
Opl,
#[cfg(feature = "json")]
#[value(name = "overpass")]
Overpass,
#[cfg(feature = "xml")]
#[value(name = "xml", alias = "osm")]
Xml,
}
#[cfg(feature = "cli")]
impl FileFormatOptions for OutputFileFormat {
fn format_error(ext: &str) -> SkywayError {
SkywayError::UnknownOutputFormat(ext.to_string())
}
}
#[cfg(not(feature = "cli"))]
#[derive(Clone, Debug)]
pub enum OutputFileFormat {
#[cfg(feature = "json")]
Json,
#[cfg(feature = "opl")]
Opl,
#[cfg(feature = "json")]
Overpass,
#[cfg(feature = "xml")]
Xml,
}
pub trait Writer {
fn write<I>(
&self,
par_iter: I,
metadata_receiver: Receiver<Metadata>,
dest: Option<PathBuf>,
) -> Result<(), SkywayError>
where
I: IntoParallelIterator<Item = ElementChunk>;
}