1
1
# Components in Rust
2
2
3
- Rust has first-class support for the component model via the [ ` cargo-component `
4
- tool] [ cargo-component ] . We will be using
5
- the ` cargo component ` subcommand to create WebAssembly components using Rust as
3
+ Rust has first-class support for the component model via the [ ` cargo-component ` tool] [ cargo-component ] .
4
+ We will be using the ` cargo component ` subcommand to create WebAssembly components using Rust as
6
5
the component's implementation language.
7
6
8
7
> [ !NOTE]
@@ -64,8 +63,7 @@ implement.
64
63
65
64
## 5. Implementing the ` Guest ` trait
66
65
67
- Implement the ` Guest ` trait in ` src/lib.rs ` , using the scaffolded code. Your
68
- code should look something like the following:
66
+ Implement the ` Guest ` trait in ` src/lib.rs ` , using the scaffolded code. Your code should look something like the following:
69
67
70
68
``` rs
71
69
{{#include .. / .. / examples / tutorial / adder / src / lib . rs}}
@@ -80,12 +78,12 @@ cargo component build --release
80
78
```
81
79
82
80
> [ !WARNING]
83
- > Building with ` --release ` removes all debug-related information from the resulting .wasm file.
81
+ > Building with ` --release ` removes all debug-related information from the resulting ` .wasm ` file.
84
82
>
85
83
> When prototyping or testing locally, you might want to avoid ` --release ` to
86
84
> obtain useful backtraces in case of errors (for example, with
87
- > ` wasmtime::WasmBacktraceDetails::Enable ` ). Note: the resulting .wasm file
88
- > will be considerably larger (likely 4MB+).
85
+ > [ ` wasmtime::WasmBacktraceDetails::Enable ` ] ( https://docs.rs/wasmtime/latest/wasmtime/enum.WasmBacktraceDetails.html#variant.Enable ) ).
86
+ > Note: the resulting ` .wasm ` file will be considerably larger (likely 4MB+).
89
87
90
88
You can use ` wasm-tools ` to output the WIT package of the component:
91
89
@@ -125,9 +123,8 @@ $ cargo run --release -- 1 2 ../add/target/wasm32-wasip1/release/adder.wasm
125
123
126
124
## Importing an interface
127
125
128
- The world file (` wit/world.wit ` ) we generated doesn't specify any imports. If
129
- your component consumes other components, you can edit the ` world.wit ` file to
130
- import their interfaces.
126
+ The world file (` wit/world.wit ` ) we generated doesn't specify any imports.
127
+ If your component consumes other components, you can edit the ` world.wit ` file to import their interfaces.
131
128
132
129
> [ !NOTE]
133
130
> This section is about importing custom WIT interfaces from library components.
0 commit comments