use crate::error::Error::IllegalArgument;
use crate::error::Result;
use crate::metadata::KvFormat;
use std::fmt::Display;
#[derive(Copy, Clone)]
pub enum WriteFormat {
ArrowLog,
CompactedLog,
CompactedKv,
}
impl WriteFormat {
pub const fn is_log(&self) -> bool {
matches!(self, Self::ArrowLog | Self::CompactedLog)
}
pub fn is_kv(&self) -> bool {
!self.is_log()
}
pub fn to_kv_format(&self) -> Result<KvFormat> {
match self {
WriteFormat::CompactedKv => Ok(KvFormat::COMPACTED),
other => Err(IllegalArgument {
message: format!("WriteFormat `{other}` is not a KvFormat"),
}),
}
}
pub fn from_kv_format(kv_format: &KvFormat) -> Result<Self> {
match kv_format {
KvFormat::COMPACTED => Ok(WriteFormat::CompactedKv),
other => Err(IllegalArgument {
message: format!("Unknown KvFormat: `{other}`"),
}),
}
}
}
impl Display for WriteFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
WriteFormat::ArrowLog => f.write_str("ArrowLog"),
WriteFormat::CompactedLog => f.write_str("CompactedLog"),
WriteFormat::CompactedKv => f.write_str("CompactedKv"),
}
}
}