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
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
use Field;
use Fields;
use Value;

use std::marker::PhantomData;

#[derive(Debug, Clone)]
pub enum Data<T> {
    Struct(Struct<T>),
    Enum(Enum<T>),
}

#[derive(Debug, Clone)]
pub enum Struct<T> {
    Unit(UnitStruct),
    Tuple(TupleStruct<T>),
    Struct(StructStruct<T>),
}

#[derive(Debug, Clone)]
pub struct UnitStruct {
    pub(crate) private: (),
}

#[derive(Debug, Clone)]
pub struct TupleStruct<T> {
    pub(crate) fields: Vec<Field<T>>,
}

#[derive(Debug, Clone)]
pub struct StructStruct<T> {
    pub(crate) fields: Vec<Field<T>>,
}

impl<T> Struct<T> {
    pub fn fields(&self) -> Fields<T>
    where
        T: Clone,
    {
        let fields = match *self {
            Struct::Unit(ref s) => Vec::new(),
            Struct::Tuple(ref s) => s.fields.clone(),
            Struct::Struct(ref s) => s.fields.clone(),
        };
        Fields {
            fields: fields.into_iter(),
        }
    }
}

impl<T> TupleStruct<T> {
    pub fn fields(&self) -> Fields<T>
    where
        T: Clone,
    {
        Fields {
            fields: self.fields.clone().into_iter(),
        }
    }
}

impl<T> StructStruct<T> {
    pub fn fields(&self) -> Fields<T>
    where
        T: Clone,
    {
        Fields {
            fields: self.fields.clone().into_iter(),
        }
    }
}

#[derive(Debug, Clone)]
pub struct Enum<T> {
    pub(crate) variants: Vec<Variant<T>>,
}

impl<'a> Enum<Value<'a>> {
    pub fn match_variant<Run>(&self, run: Run) -> Value<'a>
    where
        Run: Fn(Variant<Value<'a>>) -> Value<'a>,
    {
        let mut arms = Vec::new();
        for variant in self.variants.clone() {
            arms.push(run(variant));
        }
        // FIXME introduce a match node
        unimplemented!()
    }
}

#[derive(Debug, Clone)]
pub enum Variant<T> {
    Unit(UnitVariant),
    Tuple(TupleVariant<T>),
    Struct(StructVariant<T>),
}

#[derive(Debug, Clone)]
pub struct UnitVariant {
    pub(crate) private: (),
}

#[derive(Debug, Clone)]
pub struct TupleVariant<T> {
    pub(crate) phantom: PhantomData<T>,
}

#[derive(Debug, Clone)]
pub struct StructVariant<T> {
    pub(crate) phantom: PhantomData<T>,
}