O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Programming WebAssembly with Rust

Book Description

WebAssembly fulfills the long-awaited promise of web technologies: fast code, type-safe at compile time, execution in the browser, on embedded devices, or anywhere else. Rust delivers the power of C in a language that strictly enforces type safety. Combine both languages and you can write for the web like never before! Learn how to integrate with JavaScript, run code on platforms other than the browser, and take a step into IoT. Discover the easy way to build cross-platform applications without sacrificing power, and change the way you write code for the web.

WebAssembly is more than just a revolutionary new technology. It's reshaping how we build applications for the web and beyond. Where technologies like ActiveX and Flash have failed, you can now write code in whatever language you prefer and compile to WebAssembly for fast, type-safe code that runs in the browser, on mobile devices, embedded devices, and more. Combining WebAssembly's portable, high-performance modules with Rust's safety and power is a perfect development combination.

Learn how WebAssembly's stack machine architecture works, install low-level wasm tools, and discover the dark art of writing raw wast code. Build on that foundation and learn how to compile WebAssembly modules from Rust by implementing the logic for a checkers game. Create wasm modules in Rust to interoperate with JavaScript in many compelling ways. Apply your new skills to the world of non-web hosts, and create everything from an app running on a Raspberry Pi that controls a lighting system, to a fully-functioning online multiplayer game engine where developers upload their own arena-bound WebAssembly combat modules.

Get started with WebAssembly today, and change the way you think about the web.

What You Need:

You'll need a Linux, Mac, or Windows workstation with an Internet connection. You'll need an up-to-date web browser that supports WebAssembly. To work with the sample code, you can use your favorite text editor or IDE. The book will guide you through installing the Rust and WebAssembly tools needed for each chapter.

Table of Contents

  1.  Acknowledgments
  2.  Introduction
    1. Today’s Web Technology
    2. The Tech of Tomorrow
    3. Who This Book Is For
    4. Why Rust?
    5. What You’ll Learn
  3. Part I. Building a Foundation
    1. 1. WebAssembly Fundamentals
      1. Introducing WebAssembly
      2. Understanding WebAssembly Architecture
      3. Building a WebAssembly Application
      4. Wrapping Up
    2. 2. Building WebAssembly Checkers
      1. Playing Checkers, the Board Game
      2. Coping with Data Structure Constraints
      3. Implementing Game Rules
      4. Moving Players
      5. Testing Wasm Checkers
      6. Wrapping Up
  4. Part II. Interacting with JavaScript
    1. 3. Wading into WebAssembly with Rust
      1. Introducing Rust
      2. Installing Rust
      3. Building Hello WebAssembly in Rust
      4. Creating Rusty Checkers
      5. Coding the Rusty Checkers WebAssembly Interface
      6. Playing Rusty Checkers in JavaScript
      7. Wrapping Up
    2. 4. Integrating WebAssembly with JavaScript
      1. Creating a Better “Hello, World”
      2. Building the Rogue WebAssembly Game
      3. Experimenting Further
      4. Wrapping Up
    3. 5. Advanced JavaScript Integration with Yew
      1. Getting Started with Yew
      2. Building a Live Chat Application
      3. Wrapping Up
  5. Part III. Working with Non-Web Hosts
    1. 6. Hosting Modules Outside the Browser
      1. How to Be a Good Host
      2. Interpreting WebAssembly Modules with Rust
      3. Building a Console Host Checkers Player
      4. Wrapping Up
    2. 7. Exploring the Internet of WebAssembly Things
      1. Overview of the Generic Indicator Module
      2. Creating Indicator Modules
      3. Building Rust Applications for ARM Devices
      4. Hosting Indicator Modules on a Raspberry Pi
      5. Hardware Shopping List
      6. Endless Possibilities
      7. Wrapping Up
    3. 8. Building WARoS—The WebAssembly Robot SystemBuilding WARoS—The WebAssembly Robot System
      1. An Homage to Crobots
      2. Designing the WARoS API
      3. Building the WARoS Match Engine
      4. Creating WebAssembly Robots
      5. Robots in the Cloud
      6. Wrapping Up
      7. Conclusion
  6. A1. WebAssembly and Serverless
    1. Serverless 101
    2. Intersection of WebAssembly and Serverless
    3. WebAssembly in the Cloud
    4. Serverless WebAssembly in the Wild
    5. Integration with OpenFaaS
  7. A2. Securing WebAssembly Modules
    1. General Security Concerns
    2. Browser-Based Attack Vectors
    3. Signing and Encrypting WebAssembly Modules