#![warn(missing_docs)]
extern crate alloc;
extern crate std;
pub mod read;
pub mod write;
#[cfg(feature = "all")]
use jaq_core::native::{run, Fun};
#[cfg(feature = "all")]
pub fn funs<D: for<'a> jaq_core::DataT<V<'a> = jaq_json::Val>>() -> impl Iterator<Item = Fun<D>> {
[read::funs::<D>(), write::funs::<D>()]
.into_iter()
.flat_map(move |funs| funs.into_vec().into_iter().map(run::<D>))
}
#[non_exhaustive]
#[derive(Copy, Clone, Debug, Default)]
pub enum Format {
Raw,
Raw0,
#[default]
Json,
Cbor,
Toml,
Xml,
Yaml,
Csv,
Tsv,
}
impl Format {
pub const ALL: &str = "raw, raw0, json, cbor, yaml, toml, xml, csv, tsv";
pub fn determine(path: &std::path::Path) -> Option<Self> {
match path.extension()?.to_str()? {
"cbor" => Some(Format::Cbor),
"toml" => Some(Format::Toml),
"xml" | "xhtml" => Some(Format::Xml),
"yml" | "yaml" => Some(Format::Yaml),
"json" => Some(Format::Json),
"csv" => Some(Format::Csv),
"tsv" => Some(Format::Tsv),
_ => None,
}
}
pub fn parse(s: &str) -> Option<Self> {
match s {
"cbor" => Some(Format::Cbor),
"raw" => Some(Format::Raw),
"raw0" => Some(Format::Raw0),
"json" => Some(Format::Json),
"toml" => Some(Format::Toml),
"xml" => Some(Format::Xml),
"yaml" => Some(Format::Yaml),
"csv" => Some(Format::Csv),
"tsv" => Some(Format::Tsv),
_ => None,
}
}
}
type BoxError = Box<dyn std::error::Error + Send + Sync>;
fn invalid_data(e: impl Into<BoxError>) -> std::io::Error {
std::io::Error::new(std::io::ErrorKind::InvalidData, e)
}
fn map_invalid_data<T>(r: Result<T, impl Into<BoxError>>) -> std::io::Result<T> {
r.map_err(invalid_data)
}