Skip to content

Commit bbedd9a

Browse files
author
Chris Nelson
committed
better docs. Hopefully not too many lies ;)
1 parent 7c7a25c commit bbedd9a

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

lib/wasmex/components.ex

+49-11
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,21 @@ defmodule Wasmex.Components do
4444
4545
The component model supports the following WIT (WebAssembly Interface Type) types:
4646
47-
### Currently Supported Types
47+
### Supported Types
4848
4949
- **Primitive Types**
5050
- Integers: `s8`, `s16`, `s32`, `s64`, `u8`, `u16`, `u32`, `u64`
5151
- Floats: `f32`, `f64`
5252
- `bool`
5353
- `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+
```
5462
5563
- **Compound Types**
5664
- `record` (maps to Elixir maps with atom keys)
@@ -86,17 +94,49 @@ defmodule Wasmex.Components do
8694
42
8795
```
8896
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+
89134
### Currently Unsupported Types
90135
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:
97137
- Resources
98138
99-
Support should be considered experimental at this point.
139+
Support for the Component Model should be considered beta quality.
100140
101141
## Options
102142
@@ -124,9 +164,7 @@ defmodule Wasmex.Components do
124164
{:ok, pid} = Wasmex.Components.start_link(%{
125165
path: "component.wasm",
126166
wasi: %Wasmex.Wasi.WasiP2Options{
127-
args: ["arg1", "arg2"],
128-
env: %{"KEY" => "value"},
129-
preopened_dirs: ["/tmp"]
167+
allow_http: true
130168
}
131169
})
132170

0 commit comments

Comments
 (0)