-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Practical WebAssembly
By :
Rust uses the LLVM compiler we'll create now to generate machine-native code. rustc uses LLVM's capability to convert the native code into a WebAssembly module. We installed Rust in the previous section; let's start converting Rust into a WebAssembly module using rustc.
We will start with Hello World:
hello_world.rs:$ touch hello_world.rs
fn main() {
println!("Hello World!");
}We have defined a main function. Similar to C, main is a special function that marks the entry point to a program after it has been compiled as an executable.
fn is the function keyword in Rust. main() is the function name.
println! is the macro. Macros in Rust allow us to abstract code at a syntactic level. A macro invocation is shorthand for an "expanded" syntactic form. This expansion...