Skip to main content

oak_wit_component/ast/
mod.rs

1#![doc = include_str!("readme.md")]
2/// WIT root node
3#[derive(Clone, Debug)]
4pub struct WitRoot {
5    /// The list of top-level items in the WIT document.
6    pub items: Vec<WitItem>,
7}
8
9/// WIT item
10#[derive(Clone, Debug)]
11pub enum WitItem {
12    /// A package declaration.
13    Package(WitPackage),
14    /// A world definition.
15    World(WitWorld),
16    /// An interface definition.
17    Interface(WitInterface),
18}
19
20/// WIT package
21#[derive(Clone, Debug)]
22pub struct WitPackage {
23    /// The name of the package.
24    pub name: String,
25}
26
27/// WIT world
28#[derive(Clone, Debug)]
29pub struct WitWorld {
30    /// The name of the world.
31    pub name: String,
32    /// The items defined in the world.
33    pub items: Vec<WitWorldItem>,
34}
35
36/// WIT world item
37#[derive(Clone, Debug)]
38pub enum WitWorldItem {
39    /// An import declaration.
40    Import(WitImport),
41    /// An export declaration.
42    Export(WitExport),
43    /// An include declaration.
44    Include(WitInclude),
45}
46
47/// WIT interface
48#[derive(Clone, Debug)]
49pub struct WitInterface {
50    /// The name of the interface.
51    pub name: String,
52    /// The items defined in the interface.
53    pub items: Vec<WitInterfaceItem>,
54}
55
56/// WIT interface item
57#[derive(Clone, Debug)]
58pub enum WitInterfaceItem {
59    Type(WitType),
60    Func(WitFunc),
61}
62
63/// WIT function
64#[derive(Clone, Debug)]
65pub struct WitFunc {
66    /// The name of the function.
67    pub name: String,
68    /// The parameters of the function.
69    pub params: Vec<WitParam>,
70    /// The optional return type of the function.
71    pub result: Option<WitTypeKind>,
72}
73
74/// WIT parameter
75#[derive(Clone, Debug)]
76pub struct WitParam {
77    /// The name of the parameter.
78    pub name: String,
79    /// The type of the parameter.
80    pub ty: WitTypeKind,
81}
82
83/// WIT type
84#[derive(Clone, Debug)]
85pub struct WitType {
86    /// The name of the type.
87    pub name: String,
88    /// The kind of the type.
89    pub kind: WitTypeKind,
90}
91
92/// WIT type kind
93#[derive(Clone, Debug)]
94pub enum WitTypeKind {
95    /// Boolean type.
96    Bool,
97    /// 32-bit unsigned integer type.
98    U32,
99    /// String type.
100    String,
101}
102
103/// WIT import
104#[derive(Clone, Debug)]
105pub struct WitImport {
106    /// The name of the imported item.
107    pub name: String,
108}
109
110/// WIT export
111#[derive(Clone, Debug)]
112pub struct WitExport {
113    /// The name of the exported item.
114    pub name: String,
115}
116
117/// WIT include
118#[derive(Clone, Debug)]
119pub struct WitInclude {
120    /// The name of the included item.
121    pub name: String,
122}