11# Components in Rust
22
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
65the component's implementation language.
76
87> [ !NOTE]
@@ -64,8 +63,7 @@ implement.
6463
6564## 5. Implementing the ` Guest ` trait
6665
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:
6967
7068``` rs
7169{{#include .. / .. / examples / tutorial / adder / src / lib . rs}}
@@ -80,12 +78,12 @@ cargo component build --release
8078```
8179
8280> [ !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.
8482>
8583> When prototyping or testing locally, you might want to avoid ` --release ` to
8684> 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+).
8987
9088You can use ` wasm-tools ` to output the WIT package of the component:
9189
@@ -125,9 +123,8 @@ $ cargo run --release -- 1 2 ../add/target/wasm32-wasip1/release/adder.wasm
125123
126124## Importing an interface
127125
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.
131128
132129> [ !NOTE]
133130> This section is about importing custom WIT interfaces from library components.
0 commit comments