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
use super::*;
use wast::component::{CoreType, CoreTypeDef};

impl<'a, 'i> IntoWasm<'a, wast::component::Type<'i>> for StructureItem
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 StructureType
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: None,
            def: self.as_wast(),
            parent: None,
            final_type: None,
        }
    }
}
impl<'a, 'i> IntoWasm<'a, CoreType<'i>> for StructureType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> CoreType<'i> {
        CoreType { span: Span::from_offset(0), id: self.symbol.as_id(), name: None, def: CoreTypeDef::Def(self.as_wast()) }
    }
}
impl<'a, 'i> IntoWasm<'a, wast::component::TypeDef<'i>> for StructureItem
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 StructureType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> wast::core::TypeDef<'i> {
        wast::core::TypeDef::Struct(self.as_wast())
    }
}

impl<'a, 'i> IntoWasm<'a, ComponentDefinedType<'i>> for StructureItem
where
    'a: 'i,
{
    fn as_wast(&'a self) -> ComponentDefinedType<'i> {
        ComponentDefinedType::Record(self.as_wast())
    }
}

impl<'a, 'i> IntoWasm<'a, StructType<'i>> for StructureType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> StructType<'i> {
        StructType { fields: self.fields.values().map(|field| field.as_wast()).collect() }
    }
}
impl<'a, 'i> IntoWasm<'a, Record<'i>> for StructureItem
where
    'a: 'i,
{
    fn as_wast(&'a self) -> Record<'i> {
        Record { fields: self.fields.values().map(|v| v.as_wast()).collect() }
    }
}

impl<'a, 'i> IntoWasm<'a, StructField<'i>> for FieldType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> StructField<'i> {
        StructField { id: self.name.as_id(), mutable: !self.readonly, ty: self.r#type.as_wast() }
    }
}

impl<'a, 'i> IntoWasm<'a, RecordField<'i>> for FieldType
where
    'a: 'i,
{
    fn as_wast(&'a self) -> RecordField<'i> {
        RecordField { name: self.name.as_ref(), ty: self.r#type.as_wast() }
    }
}