#![warn(missing_docs)]
#[cfg(feature = "csv_ds")]
#[derive(Debug)]
pub struct CSVDataSource {
path: std::path::PathBuf,
}
#[cfg(feature = "csv_ds")]
impl super::DataSource for CSVDataSource {
fn srid(&self) -> Option<u32> {
None
}
}
#[cfg(feature = "csv_ds")]
impl CSVDataSource {
pub fn from(s: &str) -> Self {
Self { path: s.into() }
}
pub fn path(&self) -> &std::path::PathBuf {
&self.path
}
}
#[macro_export]
macro_rules! gen_csv_ds {
($vis:vis, $name:expr, $path:expr, $feature:expr) => {
::paste::paste! {
#[derive(Debug)]
$vis struct [<$name CSV>](::ogc_cql2::CSVDataSource);
impl [<$name CSV>] {
$vis fn new() -> Self {
Self(::ogc_cql2::CSVDataSource::from($path))
}
$vis fn reader(&self) -> Result<::csv::Reader<::std::fs::File>, MyError> {
let file = ::std::fs::File::open(self.0.path())?;
Ok(::csv::Reader::from_reader(file))
}
}
impl ::core::fmt::Display for [<$name CSV>] {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write!(f, "{}CSV({})", $name, $path)
}
}
impl ::ogc_cql2::IterableDS for [<$name CSV>] {
type Item = $feature;
type Err = MyError;
fn iter(&self) -> Result<impl Iterator<Item = Result<$feature, Self::Err>>, Self::Err> {
let file = ::std::fs::File::open(&self.0.path())?;
let rdr = ::csv::Reader::from_reader(file);
let it = rdr.into_deserialize().map(|res| res.map_err(MyError::from));
Ok(it)
}
}
}
}
}