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
use super::*;
use crate::StructureItem;
use wast::component::{Variant, VariantCase};

impl<'a, 'i> IntoWasm<'a, wast::component::Type<'i>> for VariantType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> wast::component::Type<'i> {
        wast::component::Type {
            span: Span::from_offset(0),
            id: WasmName::id(self.symbol.as_ref()),
            name: Some(NameAnnotation { name: self.symbol.as_ref() }),
            exports: Default::default(),
            def: self.as_wast(),
        }
    }
}

impl<'a, 'i> IntoWasm<'a, wast::core::Type<'i>> for VariantType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> wast::core::Type<'i> {
        wast::core::Type {
            span: Span::from_offset(0),
            id: WasmName::id(self.symbol.as_ref()),
            name: Some(NameAnnotation { name: self.symbol.as_ref() }),
            def: self.as_wast(),
            parent: None,
            final_type: None,
        }
    }
}

impl<'a, 'i> IntoWasm<'a, wast::component::TypeDef<'i>> for VariantType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> wast::component::TypeDef<'i> {
        wast::component::TypeDef::Defined(self.as_wast())
    }
}
impl<'a, 'i> IntoWasm<'a, wast::core::TypeDef<'i>> for VariantType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> wast::core::TypeDef<'i> {
        // wast::core::TypeDef::Struct(self.as_wast())
        unimplemented!()
    }
}
impl<'a, 'i> IntoWasm<'a, ComponentDefinedType<'i>> for VariantType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> ComponentDefinedType<'i> {
        ComponentDefinedType::Variant(self.as_wast())
    }
}

impl<'a, 'i> IntoWasm<'a, Variant<'i>> for VariantType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> Variant<'i> {
        Variant { cases: self.fields.values().map(|s| s.as_wast()).collect() }
    }
}

impl<'a, 'i> IntoWasm<'a, VariantCase<'i>> for StructureItem
where
    'a: 'i,
{
    fn as_wast(&'a self) -> VariantCase<'i> {
        VariantCase { span: Span::from_offset(0), id: self.symbol.as_id(), name: "", ty: None, refines: None }
    }
}