Please install the prerequisites first!
$ docker run --rm --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm secondstate/rust-example-control:latest
Hello WasmEdge!
Howdy WasmEdge!
Hola WasmEdge!
Bonjour WasmEdge!
guten tag WasmEdge!
WasmEdge 你好!
こんにちは WasmEdge!
Salve WasmEdge!
Salve WasmEdge!
The src/main.rs
source code shows
- The
for
loop starts from value0
and repeats10
times, each increasing by1
. - The
match
clause matches the control variable to specific values and branches to the corresponding statements. If control variable does not match any listed value, it will match to the_
branch.
Compile the Rust source code project to a Wasm bytecode file.
$ cargo build --target wasm32-wasi --release
Run the Wasm bytecode file in WasmEdge CLI.
$ wasmedge ../target/wasm32-wasi/release/control.wasm
Hello WasmEdge!
Howdy WasmEdge!
Hola WasmEdge!
Bonjour WasmEdge!
guten tag WasmEdge!
WasmEdge 你好!
こんにちは WasmEdge!
Salve WasmEdge!
Salve WasmEdge!
The Dockerfile
follows the above steps to build and package a lightweight OCI-compliant container image for the Wasm app.
Now, we need to publish the container image to Docker Hub.
You just need to specify that the WasmEdge application image is for the wasi/wasm
platform.
$ docker buildx build --platform wasi/wasm -t secondstate/rust-example-control .
... ...
$ docker push secondstate/rust-example-control