Skip to content

Instantly share code, notes, and snippets.

Created Feb 24, 2019
What would you like to do?
Hello World Rust Wasm Sample App
// Define a function that is imported into the module.
// By default, the "env" namespace is used.
extern "C" {
fn print_str(ptr: *const u8, len: usize);
// Define a string that is accessible within the wasm
// linear memory.
static HELLO: &'static str = "Hello, World!";
// Export a function named "hello_wasm". This can be called
// from the embedder!
pub extern fn hello_wasm() {
// Call the function we just imported and pass in
// the offset of our string and its length as parameters.
unsafe {
print_str(HELLO.as_ptr(), HELLO.len());