Advanced Hands-on Rust
Level up Your Coding Skills
by Herbert Wolverson
Accelerate your Rust development with reusable libraries, and build a
game development toolkit that helps you quickly create games using the
Bevy Engine. Improve your code with testing, benchmarking, and
optimization. Unlock Rust’s trait and generic metaprogramming systems to
develop code that adapts to fit your needs. Customize libraries with
feature flags, and customize language syntax with macros. Master
concurrency with threads and asynchronous programming. Structure your
programs with reusable state management, menus, user interface elements,
and asset management. Quickly build games with reusable physics and
collision detection. Make your games pop with animations, particles, and
rendering tricks, including parallax layering.
Printed in full color.
Accelerate your Rust development with intermediate to advanced concepts.
Build reusable libraries; unleash generics, traits, macros, and more as
you level up your Rust skills. Apply your skills to build a game
development toolkit that helps you quickly build 2D games without
reinventing the wheel when you start a new project.
Each chapter in this book includes hands-on, practical development using
intermediate through advanced Rust. Make learning fun by building games
as you apply language concepts. Develop several games and build the
tools you need to unleash your creativity or apply the concepts to your
own Rust projects.
Improve your code with testing, benchmarking, and optimization. Unlock
the power of Rust’s trait and generic metaprogramming systems to create
code that adapts to fit your needs. Customize libraries with feature
flags, and customize language syntax with macros. Structure your code
with reusable state management, menus, user interface elements, and
asset management. Quickly build games with reusable physics and
collision detection. Make your games pop with animations, particles, and
rendering tricks, including parallax layering.
This book is the ideal follow-up to take the skills you gained in
Hands-on Rust to
the next level—or it can be read stand-alone once you’ve mastered
basic Rust.
What You Need
- A computer running Windows, Mac OS, or Linux.
- A reasonably modern video card capable of running Vulkan, Metal, or
DirectX 12.
- An installed Rust development system.
Resources
Releases:
- B4.0 2025/04/10
- B3.0 2024/11/19
- B2.0 2024/07/29
- B1.0 2024/05/22
Note: Contents and extracts of beta books will change as the book is developed.
- Preface

- Getting Started
- Set up Rust and the Bevy Engine
- Checking Your Rust Version
- Setting Up a Workspace
- Creating Your First Workspace
- Bootstrapping Bevy
- Reviewing the Entity Component System
- Saying Hello to Bevy
- Displaying a Graphic with Bevy
- Moving Entities with Bevy
- Wrapping Up
- Your First Library
- Create and Test Your First Library
- Hello, Library World
- Generating Random Numbers as a Library Service
- Unit Testing your Random Number Generator
- Integration Testing your Random Number Generator
- Creating Generically Typed Random Numbers
- Using Inclusive Ranges
- Working with Generic Functions
- Wrapping Up
- Optimize and Benchmark Your Library
- Measuring Random Number Generator Performance
- Changing Random Algorithm
- Testing your Feature Flags
- Optimizing for Bevy
- Scheduling and Mutability
- Wrapping Up
- Document Your Library
- Documenting Rust Code
- Working with Block-level Documentation
- Documenting Functions
- Including Code Examples
- Wrapping Up
- Flappy Dragon Flies Again
- Build Reusable Game State Management
excerpt
- Setting up Flappy Dragon
- Understanding Bevy and Game States
- Modeling Game State
- Building a State Management Plugin
- Adding Game Menus
- Tidying Unwieldy Syntax with Macros
- Updating Pig to Use Menus
- Wrapping Up
- Manage Your Game Assets
- Understanding Bevy Assets
- Building an Asset Manager
- Creating a Loading Screen
- Adding Sound to Flappy Dragon
- Wrapping Up
- Teach Your Dragon to Fly
excerpt
- Adding Frame-Based Animation
- Simulating Movement with Parallax Layers
- Creating Consistent Movement with Physics
- Wrapping Up
- Build Obstacles and Collision Detection
excerpt
- Building a Collision-Detection Test-bed
- Removing Square Roots from Distance Calculations
- Improving Collision Detection with Bounding Boxes
- Reducing Collision Checks with Spatial Partitioning
- Upgrading Quad-Tree to a Library Service
- Wrapping Up
- Smooth Physics with Tweening
- Smoothly Integrating Physics Steps
- Rotating Your Dragon
- Predicting Imminent Collisions
- Wrapping Up
- Mars Base One
- Welcome to Mars Base One
- Building a Mars Base One Outline
- Creating a Starting Point
- Adding a Ship
- Moving the Ship
- Adding Game Over Conditions
- Wrapping Up
- Build a Mining Outpost on Mars
- Zooming In
- Making the Camera Follow the Player
- Building a Martian Mining Outpost
- Carving a Linear Corridor Between Rooms
- Bouncing Off Walls
- Adding a Background Thread for World Building
- Wrapping Up
- Optimize Mars Base One
- Displaying the Frame Rate
- Making a Mesh
- Optimizing Collision Detection
- Adding Visual Embellishments
- Wrapping Up
- Add Miners and Energy Shields
- Adding Some Graphics
- Placing Miners, Batteries and Fuel Tanks
- Adding Shields and Fuel
- Adding Particle Bursts
- A Generic System for Collecting Things
- Depleting Shields
- Running out of Fuel
- Winning the Game
- Finalize the Systems
- Wrapping Up
- Build a High Score Server
- Calculating Scores
- Passing the Score to the Game Over Phase
- Serializing Scores
- Submitting Scores with Ureq
- Building a Server
- Displaying Scores
- Displaying High Scores in the Game
- Wrap-Up
- Library Curation
- Share Your Library
- Is Your Library Worth Sharing?
- Is Your Library Ready to Share?
- Choosing the Right License
- Keeping Your Secrets
- Collaborating with Others
- Preparing Your Library for Sharing
- Wrapping Up
Author
Herbert Wolverson has worked as a programmer and an indie game
developer since the late 1990s. He’s taught programming and IT skills at
a variety of levels, contributes to multiple open source projects, and
is active in the game development scene.