You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
935 B
42 lines
935 B
3 years ago
|
//! The available formats to convert
|
||
|
use super::*;
|
||
|
use processor::Processor;
|
||
|
|
||
|
/// All formats and their associated processor
|
||
|
pub enum Format
|
||
|
{
|
||
|
Json(processor::Json),
|
||
|
SExpr(processor::Sexpr),
|
||
|
CBor(processor::Cbor),
|
||
|
}
|
||
|
|
||
|
impl Format
|
||
|
{
|
||
|
/// The processor for this format
|
||
|
pub fn processor(&self) -> &(dyn Processor + 'static)
|
||
|
{
|
||
|
match &self {
|
||
|
Self::Json(a) => a,
|
||
|
Self::SExpr(a) => a,
|
||
|
Self::CBor(a) => a,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// The processor for this format
|
||
|
pub fn processor_mut(&mut self) -> &mut (dyn Processor + 'static)
|
||
|
{
|
||
|
match self {
|
||
|
Self::Json(a) => a,
|
||
|
Self::SExpr(a) => a,
|
||
|
Self::CBor(a) => a,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// All format objects and their name(s)
|
||
|
pub static FORMATS: &[(&'static [&'static str], Format)] = &[
|
||
|
(&["json"], Format::Json(processor::Json)),
|
||
|
(&["s-expression", "sexpr"], Format::SExpr(processor::Sexpr)),
|
||
|
(&["cbor"], Format::CBor(processor::Cbor)),
|
||
|
];
|