ebook img

Programming WebAssembly with Rust PDF

228 Pages·03.09 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Programming WebAssembly with Rust

Prepared exclusively for luming Under Construction: The book you’re reading is still under development. As part of our Beta book program, we’re releasing ß this copy well before a normal book would be released. That way you’re able to get this content a couple of months before it’s available in finished form, and we’ll get feedback to make the book even better. The idea is that everyone wins! Be warned: The book has not had a full technical edit, so it will contain errors. It has not been copyedited, so it will be full of typos, spelling mistakes, and the occasional creative piece of grammar. And there’s been no effort spent doing layout, so you’ll find bad page breaks, over-long code lines, incorrect hyphen- ation, and all the other ugly things that you wouldn’t expect to see in a finished book. It also doesn't have an index. We can’t be held liable if you use this book to try to create a spiffy application and you somehow end up with a strangely shaped farm implement instead. Despite all this, we think you’ll enjoy it! Download Updates: Throughout this process you’ll be able to get updated ebooks from your account at pragprog.com/my_account. When the book is com- plete, you’ll get the final version (and subsequent updates) from the same ad- dress. Send us your feedback: In the meantime, we’d appreciate you sending us your feedback on this book at pragprog.com/titles/khrust/errata, or by using the links at the bottom of each page. Thank you for being part of the Pragmatic community! Andy Prepared exclusively for luming Programming WebAssembly with Rust Unified Development for Web, Mobile, and Embedded Applications Kevin Hoffman The Pragmatic Bookshelf Raleigh, North Carolina Prepared exclusively for luming Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade- marks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic books, screencasts, and audio books can help you and your team create better software and have more fun. Visit us at https://pragprog.com. For sales, volume licensing, and support, please contact [email protected]. For international rights, please contact [email protected]. Copyright © 2019 The Pragmatic Programmers, LLC. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. ISBN-13: 978-1-68050-636-5 Book version: B4.0—March 5, 2019 Prepared exclusively for luming For my grandfather—Walter K. MacAdam— inventor, tinkerer, and IEEE president. He quietly supported my exposure to computers and programming throughout my childhood, often in ways I didn’t know until after his death. I always wanted to grow up to be like him, and I only wish he could’ve seen this book. Prepared exclusively for luming Prepared exclusively for luming Contents Change History . . . . . . . . . . . . ix Acknowledgments . . . . . . . . . . . xi Introduction . . . . . . . . . . . . xiii Part I — Building a Foundation 1. WebAssembly Fundamentals . . . . . . . . . 3 Introducing WebAssembly 3 Understanding WebAssembly Architecture 8 Building a WebAssembly Application 12 Wrapping Up 16 2. Building WebAssembly Checkers . . . . . . . 19 Playing Checkers, the Board Game 19 Coping with Data Structure Constraints 20 Implementing Game Rules 34 Moving Players 35 Testing Wasm Checkers 38 Wrapping Up 41 Part II — Interacting with JavaScript 3. Wading into WebAssembly with Rust . . . . . . . 45 Introducing Rust 45 Installing Rust 47 Building Hello WebAssembly in Rust 47 Creating Rusty Checkers 50 Coding the Rusty Checkers WebAssembly Interface 60 Prepared exclusively for luming • Contents vi Playing Rusty Checkers in JavaScript 64 Wrapping Up 65 4. Integrating WebAssembly with JavaScript . . . . . 67 Creating a Better “Hello, World” 67 Building the Rogue WebAssembly Game 73 Experimenting Further 87 Wrapping Up 88 5. Advanced JavaScript Integration with Yew . . . . . 89 Getting Started with Yew 89 Building a Live Chat Application 99 Wrapping Up 113 Part III — Working with Non-Web Hosts 6. Hosting Modules Outside the Browser . . . . . . 117 How to Be a Good Host 117 Interpreting WebAssembly Modules with Rust 119 Building a Console Host Checkers Player 122 Wrapping Up 131 7. Exploring the Internet of WebAssembly Things . . . . 133 Overview of the Generic Indicator Module 134 Creating Indicator Modules 137 Building Rust Applications for ARM Devices 142 Hosting Indicator Modules on a Raspberry Pi 144 Hardware Shopping List 153 Endless Possibilities 154 Wrapping Up 156 8. Building WARoS—The WebAssembly Robot System . . . 157 An Homage to Crobots 158 Designing the WARoS API 159 Building the WARoS Match Engine 164 Creating WebAssembly Robots 188 Robots in the Cloud 193 Wrapping Up 194 Conclusion 194 A1. WebAssembly and Serverless . . . . . . . . 197 Serverless 101 197 Prepared exclusively for luming • Contents vii Intersection of WebAssembly and Serverless 198 WebAssembly in the Cloud 198 Serverless WebAssembly in the Wild 199 Integration with OpenFaaS 201 A2. Securing WebAssembly Modules . . . . . . . 203 General Security Concerns 203 Browser-Based Attack Vectors 203 Signing and Encrypting WebAssembly Modules 204 Index . . . . . . . . . . . . . . 209 Prepared exclusively for luming Change History The book you’re reading is in beta. This means that we update it frequently. Here is the list of the major changes that have been made at each beta release of the book, with the most recent change first. B4.0: March 5, 2019 • Production is complete. Now it’s on to layout and the printer. B3.0: January 16, 2019 • Added appendices. • Corrected minor errata. • Content-complete and heading to production. B2.0: December 12, 2018 • Added Chapter 7. • Corrected minor errata. B1.0: November 28, 2018 • Initial beta release. Prepared exclusively for luming report erratum • discuss

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.