use crate::field_type::Type;
use std::fmt;
#[derive(Debug, Clone)]
pub struct Metadata {
pub dialect: Dialect,
pub avg_record_len: usize,
pub num_fields: usize,
pub fields: Vec<String>,
pub types: Vec<Type>,
}
impl Metadata {
pub const fn new(
dialect: Dialect,
avg_record_len: usize,
num_fields: usize,
fields: Vec<String>,
types: Vec<Type>,
) -> Self {
Self {
dialect,
avg_record_len,
num_fields,
fields,
types,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Dialect {
pub delimiter: u8,
pub header: Header,
pub quote: Quote,
pub flexible: bool,
pub is_utf8: bool,
}
impl Default for Dialect {
fn default() -> Self {
Self {
delimiter: b',',
header: Header::default(),
quote: Quote::Some(b'"'),
flexible: false,
is_utf8: true,
}
}
}
impl Dialect {
pub const fn new(
delimiter: u8,
header: Header,
quote: Quote,
flexible: bool,
is_utf8: bool,
) -> Self {
Self {
delimiter,
header,
quote,
flexible,
is_utf8,
}
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Header {
pub has_header_row: bool,
pub num_preamble_rows: usize,
}
impl Header {
pub const fn new(has_header_row: bool, num_preamble_rows: usize) -> Self {
Self {
has_header_row,
num_preamble_rows,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Quote {
None,
Some(u8),
}
impl Default for Quote {
fn default() -> Self {
Quote::Some(b'"')
}
}
impl Quote {
#[inline]
pub fn char(&self) -> Option<u8> {
match self {
Quote::None => None,
Quote::Some(c) => Some(*c),
}
}
}
impl fmt::Display for Quote {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Quote::None => write!(f, "none"),
Quote::Some(c) => write!(f, "{}", *c as char),
}
}
}