-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhlist.rs
33 lines (26 loc) · 1.11 KB
/
hlist.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::fmt::{self, Debug};
pub struct HNil;
pub struct HCons<H, T: HList>(H, T);
pub trait HList {}
impl HList for HNil {}
impl<H, T: HList> HList for HCons<H, T> {}
impl Debug for HNil {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
fmt.write_str("HNil")
}
}
impl<H: Debug, T: HList + Debug> Debug for HCons<H, T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
try!(self.0.fmt(fmt)); self.1.fmt(fmt)
}
}
#[macro_export]
macro_rules! hlist({ } => { $crate::hlist::Nil } ; { $ head : expr } => {
$crate::hlist::HCons ( $ head , $crate::hlist::HNil ) } ; {
$ head : expr , $ ( $ tail : expr ) , * } => {
$crate::hlist::HCons ( $ head , hlist ! ( $ ( $ tail ) , * ) ) } ;);
#[macro_export]
macro_rules! HList({ } => { $crate::hlist::HNil } ; { $ head : ty } => {
$crate::hlist::HCons < $ head , $crate::hlist::HNil > } ; {
$ head : ty , $ ( $ tail : ty ) , * } => {
$crate::hlist::HCons < $ head , HList ! ( $ ( $ tail ) , * ) > } ;);