use std::{pin::Pin, sync::Arc};
use async_executor::Executor;
use thiserror::Error;
use crate::{io::WritableFile, schema::EntityStream};
mod json_virtual;
mod flat_file;
#[cfg(feature = "csv")]
mod csv;
#[cfg(feature = "izs")]
mod izs;
#[derive(Error, Debug)]
pub enum ExportError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Unsupported schema: {0}")]
UnsupportedSchema(String),
#[error("Failed to read input: {0}")]
Source(String),
#[error("{0}")]
UnsupportedStream(String),
#[error("{0}")]
InvalidFile(String),
}
pub struct ExportFormat {
pub name: &'static str,
pub description: &'static str,
pub extension: &'static str,
pub export: fn (executor: Arc<Executor<'static>>, EntityStream, Box<dyn WritableFile>) -> Pin<Box<dyn Future<Output=Result<(), ExportError>> + Send>>,
}
impl ExportFormat {
pub fn export(&self, file: Box<dyn WritableFile>, executor: Arc<Executor<'static>>, entity: EntityStream) -> Pin<Box<dyn Future<Output=Result<(), ExportError>> + Send>> {
(self.export)(executor, entity, file)
}
}
pub const VIRTUAL: ExportFormat = ExportFormat {
name: "virtual",
description: "Iguazu Virtual JSON",
extension: ".iguazu.json",
export: json_virtual::export,
};
#[cfg(feature = "izs")]
pub const IZS: ExportFormat = ExportFormat {
name: "izs",
description: "Iguazu Pack",
extension: ".izs",
export: izs::export,
};
pub const EXPORTERS: &[ExportFormat] = &[
VIRTUAL,
#[cfg(feature = "izs")]
IZS,
];