📄️ Set up Rust toolchain
In the following chapters, we will show how to build and compile Rust programs into WASM bytecode and then run them in WasmEdge.
📄️ Hello world
Before we start, ensure you have Rust and WasmEdge installed.
📄️ Access OS services
The WASI (WebAssembly Systems Interface) standard is designed to allow WebAssembly applications to access operating system services. The wasm32-wasi target in the Rust compiler supports WASI. This section will use an example project to show how to use Rust standard APIs to access operating system services.
🗃️ HTTP services
2 個項目
🗃️ Socket networking
2 個項目
🗃️ AI inference
8 個項目
🗃️ Database drivers
4 個項目
📄️ Dapr services
Second State launched a new WebAssembly-based SDK for the Dapr API, which provides an easy way for Rust-based microservices in WasmEdge to interact with Dapr APIs and sidecar services.
📄️ Crypto for WASI
While optimizing compilers could allow efficient implementation of cryptographic features in WebAssembly, there are several occasions where a host implementation is more desirable. WASI-crypto aims to fill those gaps by defining a standard interface as a set of APIs. Currently not support Android.
📄️ Bindgen of Rust Functions
If your Rust program has a main() function, you could compile it into WebAssembly, and run it using the wasmedge CLI tool as a standalone application. However, a far more common use case is to compile a Rust function into WebAssembly, and then call it from a host application. That is known as an embedded WASM function. The host application uses WasmEdge language SDKs (e.g., Go, Rust, C, Python (WIP) and Java (WIP)) to call those WASM functions compiled from Rust source code. In this chapter, we will cover a little about WasmEdge-bindgen, and you can find more information here
📄️ Command interface
WASI enables WebAssembly programs to call standard library functions in the host operating system. It does so through a fine-grained security model known as “capability-based security”. The WebAssembly VM owner can grant access to host system resources when the VM starts. The program cannot access resources (e.g., file folders) that are not explicitly allowed.
📄️ Server-side rendering
Frontend web frameworks allow developers to create web apps in a high-level language and component model. The web app is built into a static website to be rendered in the browser. While many frontend web frameworks are based on JavaScript, such as React and Vue, Rust-based frameworks are also emerging as the Rust language gains traction among developers. Those web frameworks render the HTML DOM UI using the WebAssembly, compiled from Rust source code. They use wasm-bindgen to tie the Rust to the HTML DOM. While these frameworks send .wasm files to the browser to render the UI on the client side, some provide the additional choice for Server-side rendering. That is to run the WebAssembly code, build the HTML DOM UI on the server, and stream the HTML content to the browser for faster performance and startup time on slow devices and networks.