use std::fmt;
const FLOAT_FORMAT_SPELLINGS: &[&str] = &["ieee-be", "ieee", "ieee-big-endian", "ibm-hex", "ibm"];
const RECORD_FORMAT_SPELLINGS: &[&str] = &["fixed", "rdw"];
const JSON_NUMBER_MODE_SPELLINGS: &[&str] = &["lossless", "native"];
const RAW_MODE_SPELLINGS: &[&str] = &["off", "record", "field", "record+rdw"];
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CodecOptionKind {
FloatFormat,
RecordFormat,
JsonNumberMode,
RawMode,
}
impl CodecOptionKind {
#[must_use]
#[inline]
pub const fn accepted_spellings(self) -> &'static [&'static str] {
match self {
Self::FloatFormat => FLOAT_FORMAT_SPELLINGS,
Self::RecordFormat => RECORD_FORMAT_SPELLINGS,
Self::JsonNumberMode => JSON_NUMBER_MODE_SPELLINGS,
Self::RawMode => RAW_MODE_SPELLINGS,
}
}
#[inline]
const fn display_name(self) -> &'static str {
match self {
Self::FloatFormat => "float format",
Self::RecordFormat => "record format",
Self::JsonNumberMode => "JSON number mode",
Self::RawMode => "raw mode",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseCodecOptionError {
kind: CodecOptionKind,
input: String,
}
impl ParseCodecOptionError {
#[inline]
pub(super) fn new(kind: CodecOptionKind, input: &str) -> Self {
Self {
kind,
input: input.to_owned(),
}
}
#[must_use]
#[inline]
pub const fn kind(&self) -> CodecOptionKind {
self.kind
}
#[must_use]
#[inline]
pub fn input(&self) -> &str {
&self.input
}
#[must_use]
#[inline]
pub const fn accepted_spellings(&self) -> &'static [&'static str] {
self.kind.accepted_spellings()
}
}
impl fmt::Display for ParseCodecOptionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"unsupported {} `{}`",
self.kind.display_name(),
self.input
)
}
}
impl std::error::Error for ParseCodecOptionError {}