Kick off your book project in 3 hours! Live workshop on Zoom. You’ll leave with a real book project, progress on your first chapter, and a clear plan to keep going. Saturday, June 6, 2026. Learn more…

Leanpub Header

Skip to main content

From Ruby to Rust

A Ruby Programmer's Guide to Learning Rust

This book is 100% completeLast updated on 2026-05-29

Take everything you know about Ruby — classes, modules, exceptions, enumerable methods — and translate it directly to Rust. No fluff, no abstract theory, just runnable Ruby-to-Rust comparisons with hands-on exercises.

Minimum price

$19.00

$29.00

You pay

Author earns

$
PDF
EPUB
WEB
About

About

About the Book

Learning a new programming language is hard. Learning one with a completely different memory model — no garbage collector, no `nil`, no inheritance — is harder.

**From Ruby to Rust** skips the abstract theory and teaches Rust the way a Rubyist actually learns: by mapping every Rust concept back to Ruby. Structs replace classes. Traits replace modules. `Result` replaces exceptions. The borrow checker replaces the garbage collector. `match` replaces `case/when`. Cargo replaces Bundler.

Each chapter starts with Ruby code you already understand, then shows the Rust equivalent — complete, runnable, and explained line by line. You'll build structs, enums, iterators, traits, and concurrent programs from the ground up, with hands-on exercises at every step.

Rust has been Stack Overflow's most loved language for years. It powers Firefox, parts of the Linux kernel, Discord's backend, Cloudflare workers, and Dropbox's storage. When performance matters and correctness is non-negotiable, teams reach for Rust. It's not a trend — it's the future of systems programming, and it's coming for backend development too.

Updated for Rust Edition 2024 and tested with Rust 1.85+, this edition covers ownership and borrowing, lifetimes, pattern matching, `Result` and `Option`, traits and generics, iterators and closures, concurrency with threads and channels, and the full Cargo ecosystem — everything you need to write production Rust.

This book was written with a Rubyist in mind. Every learning metaphor is based on Ruby. If you know Ruby and want to add Rust to your toolkit, this is the book.

Share this book

Categories

Author

About the Author

Joel Bryan Juliano

Hi, I'm Joel.

I am Senior Software Engineer with 20+ years of experience.

And with over 20 years in the game, I’ve seen it all and loved every minute of it.

Originally from the Philippines, I am now a Dutchman living in Amsterdam together with my family.

My journey has taken me through a variety of industries, from sports streaming to cybersecurity, and everything in between.

Along the way, I’ve picked up a diverse set of skills and experiences, in which I document into books.

Contents

Table of Contents

Preface

Introduction

  1. Who This Book Is For
  2. How to Use This Book
  3. What This Book Is Not
  4. A Note on Editions
  5. About the Author

Chapter 1: Getting Started

  1. Installing Rust
  2. Creating a New Project
  3. The Main Function
  4. println! — Rust’s puts
  5. String Interpolation with format!
  6. Functions
  7. Chapter Exercises
  8. Summary

Chapter 2: Variables, Types, and Mutability

  1. let — Variable Binding
  2. Type Inference and Explicit Types
  3. Scalar Types
  4. Constants
  5. Shadowing
  6. Compound Types: Tuples and Arrays
  7. Chapter Exercises
  8. Summary

Chapter 3: Structs, Methods, and impl Blocks

  1. Defining a Struct
  2. Creating Instances
  3. Accessing Fields
  4. Struct Update Syntax
  5. Tuple Structs
  6. Unit Structs
  7. impl Blocks — Adding Methods
  8. Associated Functions (Constructors)
  9. Multiple impl Blocks
  10. The Debug Trait
  11. Ruby Class vs Rust Struct: Side by Side
  12. Chapter Exercises
  13. Summary

Chapter 4: Enums and Pattern Matching

  1. Defining an Enum
  2. match — Rust’s case/when
  3. if let — Concise Single-Pattern Matching
  4. Option — The Billion-Dollar Null Replacement
  5. Result — Handling Fallible Operations
  6. Pattern Matching Power Tools
  7. Chapter Exercises
  8. Summary

Chapter 5: Ownership and Borrowing

  1. The Problem Ownership Solves
  2. The Three Ownership Rules
  3. Move Semantics
  4. Copy Types
  5. Clone — Explicit Deep Copy
  6. Ownership and Functions
  7. Borrowing and References
  8. The Borrowing Rules
  9. Dangling References
  10. Slices — References to a Portion
  11. Ownership in Structs
  12. Ruby vs Rust: Memory Management Side by Side
  13. Chapter Exercises
  14. Summary

Chapter 6: Collections and Iterators

  1. Vec — Rust’s Array
  2. HashMap — Rust’s Hash
  3. Iterators — Rust’s Enumerable
  4. Collecting Results
  5. Collecting into Result and Option
  6. Closures
  7. Real-World Iterator Example
  8. Chapter Exercises
  9. Summary

Chapter 7: Error Handling

  1. Result — Errors as Values
  2. The ? Operator — Propagate Errors Up
  3. unwrap and expect
  4. Handling Different Error Types
  5. panic! — When Recovery Is Impossible
  6. Error Handling: Ruby vs Rust
  7. Chapter Exercises
  8. Summary

Chapter 8: Traits and Generics

  1. Defining a Trait
  2. Default Trait Implementations
  3. Trait Bounds and impl Trait
  4. Generics — Type Parameters
  5. Derive Macros — Auto-Generating Trait Implementations
  6. Trait Objects — Dynamic Dispatch
  7. Common Standard Library Traits
  8. Traits vs Ruby Modules: Side by Side
  9. Chapter Exercises
  10. Summary

Chapter 9: Strings and Text

  1. String and &str — Owned vs Borrowed
  2. Converting Between String and &str
  3. String Concatenation and format!
  4. Indexing into Strings
  5. Common String Operations
  6. Parsing Strings into Numbers
  7. Building Strings Efficiently
  8. Bytes, Chars, and Grapheme Clusters
  9. Regular Expressions
  10. Raw String Literals
  11. Ruby vs Rust: String Operations Cheat Sheet
  12. Chapter Exercises
  13. Summary

Chapter 10: Lifetimes

  1. Why Lifetimes Exist
  2. Lifetime Annotation Syntax
  3. When the Compiler Needs Lifetime Annotations
  4. Lifetime Elision Rules
  5. Lifetimes in Structs
  6. Static Lifetime
  7. Lifetime Annotations in Practice
  8. Ruby vs Rust: Lifetimes are Not in Ruby
  9. Chapter Exercises
  10. Summary

Chapter 11: Concurrency

  1. Spawning Threads
  2. Message Passing with Channels
  3. Shared State with Arc and Mutex
  4. Send and Sync — The Safety Traits
  5. The Rayon Crate — Parallel Iterators
  6. Concurrency Patterns: Ruby vs Rust
  7. Choosing a Concurrency Approach
  8. Chapter Exercises
  9. Summary

Chapter 12: Modules, Crates, and Testing

  1. Packages and Crates
  2. Modules — Organizing Code with mod
  3. Visibility with pub
  4. use — Bringing Names into Scope
  5. External Crates and Cargo.toml
  6. Testing
  7. Common Project Layout
  8. Ruby vs Rust: Project Structure Side by Side
  9. Chapter Exercises
  10. Summary

Appendix A: The Rust Toolchain

  1. rustup — The Toolchain Manager
  2. Cargo Commands Reference
  3. Editor Setup
  4. Clippy — The Linter
  5. rustfmt — The Formatter
  6. Useful Crates by Category
  7. Rust Documentation
  8. CI Configuration (GitHub Actions)
  9. Next Steps After This Book

Appendix B: Exercise Answers

  1. Chapter 1
  2. Chapter 2
  3. Chapter 4
  4. Chapter 5
  5. Chapter 6
  6. Chapter 7
  7. Chapter 8
  8. Chapter 9
  9. Chapter 10
  10. Chapter 11
  11. Chapter 12

Glossary

Acknowledgements

Credits

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub