Rust
You can use Wasmer in your Rust projects to execute WebAssembly modules securely and conveniently.
Some of our language extensions are using the Wasmer Rust crate under the hood.
Check out the Wasmer Rust docs here:
To be able to run Wasmer inside our Rust application, we will need Rust installed in our system.
curl https://sh.rustup.rs -sSf | sh
To install Rust on Windows, download and run rustup-init.exe, then follow the onscreen instructions.
To ensure this is installed, let's run the following:
rustc -V # This will display the Rust version
cargo -V # This will display the Cargo version
If these commands work, Rust is successfully installed!
Wasmer publishes various Crates:
- Compilers:
- Integrations:
-
wasmer-wasi
: Wasmer's implementation of the WASI standard. This allows you to run Wasm in a POSIX-like environment with a file system and permissions. -
wasmer-emscripten
: Wasmer's implementation of the Emscripten ABI. This allows you to run Wasm in a less sandboxed way in a 32bit Linux-like environment.
Now let's setup your Rust environment!
Now it's time to create a new project and add Wasmer as a dependency:
cargo new wasmer-project --bin
This should generate two important files for us,
Cargo.toml
and src/main.rs
. The Cargo.toml
is a file that describes your project and its dependencies. The src/main.rs
is the entry point for your project, and contains the fn main() { .. }
that is run when the project is executed.Now, edit the
Cargo.toml
file to add wasmer
as a dependency:[dependencies]
# The Wasmer API
wasmer = "3.0"
Next, let's take a look at some examples!
Last modified 4mo ago