@@ -44,13 +44,21 @@ defmodule Wasmex.Components do
44
44
45
45
The component model supports the following WIT (WebAssembly Interface Type) types:
46
46
47
- ### Currently Supported Types
47
+ ### Supported Types
48
48
49
49
- **Primitive Types**
50
50
- Integers: `s8`, `s16`, `s32`, `s64`, `u8`, `u16`, `u32`, `u64`
51
51
- Floats: `f32`, `f64`
52
52
- `bool`
53
53
- `string`
54
+ - `char` (maps to Elixir strings with a single character)
55
+ ```wit
56
+ char
57
+ ```
58
+ ```elixir
59
+ "A" # or from a code point
60
+ 937 # Ω
61
+ ```
54
62
55
63
- **Compound Types**
56
64
- `record` (maps to Elixir maps with atom keys)
@@ -86,17 +94,49 @@ defmodule Wasmex.Components do
86
94
42
87
95
```
88
96
97
+ - `enum` (maps to Elixir atoms)
98
+ ```wit
99
+ enum size { s, m, l }
100
+ ```
101
+ ```elixir
102
+ :s # or :m or :l
103
+ ```
104
+
105
+ - `variant` (tagged unions, maps to atoms or tuples)
106
+ ```wit
107
+ variant filter { all, none, lt(u32) }
108
+ ```
109
+ ```elixir
110
+ :all # variant without payload
111
+ :none # variant without payload
112
+ {:lt, 7} # variant with payload
113
+ ```
114
+
115
+ - `flags` (maps to Elixir maps with boolean values)
116
+ ```wit
117
+ flags permission { read, write, exec }
118
+ ```
119
+ ```elixir
120
+ %{read: true, write: true, exec: false}
121
+ # Note: When returned from WebAssembly, only the flags set to true are included
122
+ # %{read: true, exec: true}
123
+ ```
124
+
125
+ - `result<T, E>` (maps to Elixir tuples with :ok/:error)
126
+ ```wit
127
+ result<u32, u32>
128
+ ```
129
+ ```elixir
130
+ {:ok, 42} # success case
131
+ {:error, 404} # error case
132
+ ```
133
+
89
134
### Currently Unsupported Types
90
135
91
- The following WIT types are not yet supported:
92
- - `char`
93
- - `variant` (tagged unions)
94
- - `enum`
95
- - `flags`
96
- - `result` types
136
+ The following WIT type is not yet supported:
97
137
- Resources
98
138
99
- Support should be considered experimental at this point .
139
+ Support for the Component Model should be considered beta quality .
100
140
101
141
## Options
102
142
@@ -124,9 +164,7 @@ defmodule Wasmex.Components do
124
164
{:ok, pid} = Wasmex.Components.start_link(%{
125
165
path: "component.wasm",
126
166
wasi: %Wasmex.Wasi.WasiP2Options{
127
- args: ["arg1", "arg2"],
128
- env: %{"KEY" => "value"},
129
- preopened_dirs: ["/tmp"]
167
+ allow_http: true
130
168
}
131
169
})
132
170
0 commit comments