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
use crate::{
BinaryReader, ComponentExternalKind, ComponentValType, FromReader, Result, SectionLimited,
};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum TypeBounds {
Eq,
}
impl<'a> FromReader<'a> for TypeBounds {
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
Ok(match reader.read_u8()? {
0x00 => TypeBounds::Eq,
x => return reader.invalid_leading_byte(x, "type bound"),
})
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ComponentTypeRef {
Module(u32),
Func(u32),
Value(ComponentValType),
Type(TypeBounds, u32),
Instance(u32),
Component(u32),
}
impl<'a> FromReader<'a> for ComponentTypeRef {
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
Ok(match reader.read()? {
ComponentExternalKind::Module => ComponentTypeRef::Module(reader.read()?),
ComponentExternalKind::Func => ComponentTypeRef::Func(reader.read()?),
ComponentExternalKind::Value => ComponentTypeRef::Value(reader.read()?),
ComponentExternalKind::Type => ComponentTypeRef::Type(reader.read()?, reader.read()?),
ComponentExternalKind::Instance => ComponentTypeRef::Instance(reader.read()?),
ComponentExternalKind::Component => ComponentTypeRef::Component(reader.read()?),
})
}
}
#[derive(Debug, Copy, Clone)]
pub struct ComponentImport<'a> {
pub name: &'a str,
pub url: &'a str,
pub ty: ComponentTypeRef,
}
impl<'a> FromReader<'a> for ComponentImport<'a> {
fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
Ok(ComponentImport {
name: reader.read()?,
url: reader.read()?,
ty: reader.read()?,
})
}
}
pub type ComponentImportSectionReader<'a> = SectionLimited<'a, ComponentImport<'a>>;