use std::marker::PhantomData;
use label::*;
pub type FieldSchema<Label, DType> = Labeled<Label, PhantomData<DType>>;
pub type FieldCons<Label, DType, Tail> = LMCons<Label, DType, Tail>;
pub type FieldPayloadCons<Label, DType, Payload, Tail> = LDVCons<Label, DType, Payload, Tail>;
#[derive(Debug, Clone)]
pub enum FieldDesignator {
Expr(String),
Idx(usize),
}
impl SelfValued for FieldDesignator {}
pub type SchemaCons<Label, DType, Tail> = FieldPayloadCons<Label, DType, FieldDesignator, Tail>;
impl<Label, DType, Tail> SchemaCons<Label, DType, Tail> {
pub fn new(src_designator: FieldDesignator, tail: Tail) -> SchemaCons<Label, DType, Tail> {
SchemaCons {
head: TypedValue::from(src_designator).into(),
tail,
}
}
}
#[macro_export]
macro_rules! schema {
() => {{
$crate::cons::Nil
}};
(fieldname $field_label:ty = $header:expr; $($rest:tt)*) => {{
use $crate::fieldlist::{FieldDesignator, SchemaCons};
SchemaCons::<
$field_label,
<$field_label as $crate::label::Typed>::DType,
_,
>::new(
FieldDesignator::Expr($header.to_string()),
schema![$($rest)*]
)
}};
(fieldindex $field_label:ty = $idx:expr; $($rest:tt)*) => {{
use $crate::fieldlist::{FieldDesignator, SchemaCons};
SchemaCons::<
$field_label,
<$field_label as $crate::label::Typed>::DType,
_,
>::new(
FieldDesignator::Idx($idx),
schema![$($rest)*]
)
}};
}