Skip to content

Commit 2f2eb70

Browse files
fix(pl/rust): add missing greet interface for runnable example
1 parent e919fe2 commit 2f2eb70

File tree

1 file changed

+27
-2
lines changed
  • component-model/src/language-support/creating-runnable-components

1 file changed

+27
-2
lines changed

component-model/src/language-support/creating-runnable-components/rust.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ contents to `runnable-example/wit/component.wit`:
3838
```wit
3939
package example:runnable;
4040
41+
interface greet {
42+
greet: func(name: string) -> string;
43+
}
44+
4145
world greeter {
46+
export greet;
4247
export wasi:cli/run@0.2.7;
4348
}
4449
```
@@ -76,8 +81,16 @@ mod bindings {
7681
/// Component off of which implementation will hang (this can be named anything)
7782
struct Component;
7883

79-
export bindings::wasi::cli::run::Guest for Component {
80-
fn run(&self) -> Result<(), ()> {
84+
/// Implementation for the `greet` interface export
85+
impl bindings::exports::example::runnable::greet::Guest for Component {
86+
fn greet(name: String) -> String {
87+
format!("Hello {name}!")
88+
}
89+
}
90+
91+
/// Implementation for `wasi:cli/run` interface export
92+
impl bindings::exports::wasi::cli::run::Guest for Component {
93+
fn run() -> Result<(), ()> {
8194
eprintln!("Hello World!");
8295
Ok(())
8396
}
@@ -92,6 +105,12 @@ To build the component, use `cargo`:
92105
cargo build --target=wasm32-wasip2
93106
```
94107

108+
The component can also be built in release mode:
109+
110+
```console
111+
cargo build --target=wasm32-wasip2 --release
112+
```
113+
95114
### 5. Run the component with `wasmtime`
96115

97116
You can run the component with `wasmtime`, and unlike a generic reactor component, you do not need to specify
@@ -142,6 +161,12 @@ To build the component, use `cargo`:
142161
cargo build --target=wasm32-wasip2
143162
```
144163

164+
The component can also be built in release mode:
165+
166+
```console
167+
cargo build --target=wasm32-wasip2 --release
168+
```
169+
145170
### 4. Run the component with `wasmtime`
146171

147172
To run your command component:

0 commit comments

Comments
 (0)