Skip to content

Commit

Permalink
Merge pull request #189 from kate-goldenring/rust-tutorial-clarification
Browse files Browse the repository at this point in the history
Clarify add implementation in Rust guide
  • Loading branch information
kate-goldenring authored Jan 14, 2025
2 parents 3e50b13 + de2c095 commit c32350f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions component-model/src/language-support/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,16 @@ $ cargo component new add --lib && cd add
Note that `cargo component` generates the necessary bindings as a module called `bindings`.

Next, update `wit/world.wit` to match `add.wit` and modify the component package reference to change the
package name to `example`. The `component` section of `Cargo.toml` should look like the following:
package name to `example:component`. The `component` section of `Cargo.toml` should look like the following:

```toml
[package.metadata.component]
package = "component:example"
package = "example:component"
```

`cargo component` will generate bindings for the world specified in a package's `Cargo.toml`. In particular, it will create a `Guest` trait that a component should implement. Since our `example` world has no interfaces, the trait lives directly under the bindings module. Implement the `Guest` trait in `add/src/lib.rs` such that it satisfied the `example` world, adding an `add` function. It should look similar to the following:
`cargo component` will generate bindings for the world specified in a package's `Cargo.toml`. In particular, it will create a `Guest` trait that a component should implement. Since our `example` world has no interfaces, the trait lives directly under the bindings module. Implement the `Guest` trait in `add/src/lib.rs` such that it satisfies the `example` world, adding an `add` function:

```rs
mod bindings;

use bindings::Guest;

struct Component;

impl Guest for Component {
Expand Down

0 comments on commit c32350f

Please sign in to comment.