Hands-on Rust
Effective Learning through 2D Game Development and Play
by Herbert Wolverson
Version: P1.0 (July 2021)
Copyright 2021 The Pragmatic Programmers, LLC. This book is licensed to the individual who purchased it. We don't copy-protect it because that would limit your ability to use it for your own purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copy with other members of your team, with friends, or via file sharing services. Thanks.
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 and the linking g device are trademarks 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.
About the Pragmatic Bookshelf
The Pragmatic Bookshelf is an agile publishing company. Were here because we want to improve the lives of developers. We do this by creating timely, practical titles, written by programmers for programmers.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
Our ebooks do not contain any Digital Restrictions Management, and have always been DRM-free. We pioneered the beta book concept, where you can purchase and read a book while its still being written, and provide feedback to the author to help make a better book for everyone. Free resources for all purchasers include source code downloads (if applicable), errata and discussion forums, all available on the book's home page at pragprog.com. Were here to make your life easier.
New Book Announcements
Want to keep up on our latest titles and announcements, and occasional special offers? Just create an account on pragprog.com (an email address and a password is all it takes) and select the checkbox to receive newsletters. You can also follow us on twitter as @pragprog.
About Ebook Formats
If you buy directly from pragprog.com, you get ebooks in all available formats for one price. You can synch your ebooks amongst all your devices (including iPhone/iPad, Android, laptops, etc.) via Dropbox. You get free updates for the life of the edition. And, of course, you can always come back and re-download your books when needed. Ebooks bought from the Amazon Kindle store are subject to Amazon's polices. Limitations in Amazon's file format may cause ebooks to display differently on different devices. For more information, please see our FAQ at pragprog.com/#about-ebooks. To learn more about this book and access the free resources, go to https://pragprog.com/book/hwrust, the book's homepage.
Thanks for your continued support,
Andy Hunt
The Pragmatic Programmers
The team that produced this book includes: Dave Rankin (CEO) Janet Furlow (COO) Tammy Coron (Managing Editor) Tammy Coron (Development Editor) Vanya Wong (Copy Editor) Potomac Indexing, LLC (Indexing) Gilson Graphics (Layout) Andy Hunt and Dave Thomas (Founders)
For customer support, please contact .
For international rights, please contact .
Table of Contents
Copyright 2021, The Pragmatic Bookshelf.
Early Praise for Hands-on Rust
One of the first books about Rust gamedev! Great at filling the gap between learning the language itself and actually writing complex applications in it. Definitely recommended for anyone interested in either game development or Rust.
Andrey Lesnikov |
Editor, Rust GameDev Newsletter |
I absolutely loved this book! Hands-on Rust is accessible, easy to read and Herbert does a great job distilling a wealth of knowledge and experience for making games in Rust.
Olivia Ifrim |
Senior Software Engineer |
Hands-on Rust marks a new level of maturity for the Rust game development ecosystem. And while the primary selling point of the book is to learn Rust and game programming in one go, theres also an immensely important lesson of creative constraints to be learned from the plain-text ASCII tooling used throughout; bracket-lib.
When the only visuals you have to play with are letters and symbols, youve no choice but to delve deep into the mechanics of your game. Herberts bracket-lib teaches a form of minimalist game design that is perfect for rapid prototyping or complex world-building, without the distraction of HD aesthetics.
Erlend Sogge Heggen |
Lead Member, Rust GameDev Working Group |
Acknowledgments
This book would not have been possible without the patience, support, and love of my wife, -Mel Wolverson.
A huge thank you is owed to my parentsRobert Wolverson and Dawn McLaren. They introduced me to computers at a tender age, taught me basic programming, and put up with years of look what I made. They instilled in me a life-long love of learning and teaching.
I would also like to thank Erlend Sogge Heggen of the Amethyst Foundation for introducing me to The Pragmatic Bookshelf . The wonderful community in r/roguelikedev on Reddit persuaded me to return to game development many years ago, and continued to provide support throughout the development of this book. Special thanks are due to Josh Geauthor of Cogmind , and Brian Bucklewof Caves of Qud famefor encouraging the whole Roguelike development community. Thanks to Steve Cotterill for writing tips and being a great sounding board while I structured the book. Finally, Walter Pearce deserves special thanks for all of the Rust help they provided.
Kent Froeschle and Stephen Turner at iZones deserve acknowledgment for their continual encouragement and work schedule flexibility, patiently dealing with both a global pandemic and my writing schedule.
This book would not be what it is without the patient and thorough help of the tech reviewers: Bas Zalmstra, Josh Snaith, Vladyslav Batyrenko, Thomas Gillen, Remco Kuijper, Forest Anderson, Olivia Ifrim, and Jurgis Balciunas.
Finally, thank you to Tammy Coronthe editorfor her help and enthusiasm on this project, keeping me focused and shepherding me through the publishing process.
Copyright 2021, The Pragmatic Bookshelf.
Preface
Rust is an exciting programming language that combines the power of C with memory safety, fearless concurrency, and productivity boosters. It offers close-to-the-metal power and performance, while also providing a safety net to avoid many of the more common bugs found in low-level languages. Because of its features, Rust is a very competitive systems and game development language and is currently enjoying rapid growth amongst industry giants, including Amazon, Google, Microsoft, and many game development houses.
A great way to learn and study Rust is through game development. Dont be discouraged by the scale and polish of AAA titles. Small indie games are fun, and hobby game development can kickstart careers in professional game dev or unrelated development fields. Every successful game developer started small, gradually gaining skills until they could work on the game of their dreams.