Preface
Introduction
Who This Book Is For
How to Use This Book
What This Book Is Not
A Note on Editions
About the Author
Chapter 1: Getting Started
Installing Rust
Creating a New Project
The Main Function
println! — Rust’s puts
String Interpolation with format!
Functions
Defining Functions
Parameters
Return Values
Cargo Commands Cheat Sheet
Chapter Exercises
Summary
Chapter 1 Quiz
3 attempts allowed
Chapter 2: Variables, Types, and Mutability
let — Variable Binding
Try It Yourself
Type Inference and Explicit Types
Try It Yourself
Scalar Types
Integers
Floats
Booleans
Characters
Try It Yourself
Constants
Try It Yourself
Shadowing
Try It Yourself
Compound Types: Tuples and Arrays
Tuples
Arrays
Try It Yourself
Chapter Exercises
Summary
Chapter 2 Quiz
3 attempts allowed
Chapter 3: Structs, Methods, and impl Blocks
Defining a Struct
Creating Instances
Accessing Fields
Try It Yourself
Struct Update Syntax
Try It Yourself
Tuple Structs
Try It Yourself
Unit Structs
impl Blocks — Adding Methods
Try It Yourself
Associated Functions (Constructors)
Try It Yourself
Multiple impl Blocks
The Debug Trait
Ruby Class vs Rust Struct: Side by Side
Chapter Exercises
Summary
Chapter 3 Quiz
3 attempts allowed
Chapter 4: Enums and Pattern Matching
Defining an Enum
Try It Yourself
match — Rust’s case/when
Matching Variants with Data
Try It Yourself
if let — Concise Single-Pattern Matching
Try It Yourself
Option — The Billion-Dollar Null Replacement
Common Option Methods
Try It Yourself
Result — Handling Fallible Operations
Pattern Matching Power Tools
Matching Ranges
Matching with Guards
@ Bindings
Try It Yourself
Chapter Exercises
Summary
Chapter 4 Quiz
3 attempts allowed
Chapter 5: Ownership and Borrowing
The Problem Ownership Solves
The Three Ownership Rules
Move Semantics
Try It Yourself
Copy Types
Clone — Explicit Deep Copy
Try It Yourself
Ownership and Functions
Borrowing and References
Mutable References
Try It Yourself
The Borrowing Rules
Multiple Immutable References — OK
Mutable + Immutable — ERROR
One Mutable — OK
Try It Yourself
Dangling References
Slices — References to a Portion
Ownership in Structs
Ruby vs Rust: Memory Management Side by Side
Chapter Exercises
Summary
Chapter 5 Quiz
3 attempts allowed
Chapter 6: Collections and Iterators
Vec — Rust’s Array
Creating Vecs
Accessing Elements
Modifying Vecs
Iterating
Try It Yourself
HashMap — Rust’s Hash
Common HashMap Operations
Building a HashMap from Tuples
Try It Yourself
Iterators — Rust’s Enumerable
Creating Iterators
Iterator Adapters (the map/select/reduce equivalents)
Try It Yourself
Collecting Results
Collecting into Result and Option
Try It Yourself
Closures
Real-World Iterator Example
Try It Yourself
Chapter Exercises
Summary
Chapter 6 Quiz
3 attempts allowed
Chapter 7: Error Handling
Result — Errors as Values
Try It Yourself
The ? Operator — Propagate Errors Up
Try It Yourself
unwrap and expect
Try It Yourself
Handling Different Error Types
Box — Catch-All
Custom Error Types
Popular Crates: thiserror and anyhow
Try It Yourself
panic! — When Recovery Is Impossible
Error Handling: Ruby vs Rust
Chapter Exercises
Summary
Chapter 7 Quiz
3 attempts allowed
Chapter 8: Traits and Generics
Defining a Trait
Try It Yourself
Default Trait Implementations
Trait Bounds and impl Trait
Try It Yourself
Generics — Type Parameters
Generic Structs
Generics in impl Blocks
Try It Yourself
Derive Macros — Auto-Generating Trait Implementations
Try It Yourself
Trait Objects — Dynamic Dispatch
Try It Yourself
Common Standard Library Traits
Display — User-Facing Formatting
From and Into — Type Conversions
Iterator
Try It Yourself
Traits vs Ruby Modules: Side by Side
Chapter Exercises
Summary
Chapter 8 Quiz
3 attempts allowed
Chapter 9: Strings and Text
String and &str — Owned vs Borrowed
String — Owned, Mutable
&str — Borrowed, Immutable
Try It Yourself
Converting Between String and &str
Try It Yourself
String Concatenation and format!
Indexing into Strings
Try It Yourself
Common String Operations
Splitting and Joining
Searching and Replacing
Trimming and Case
Try It Yourself
Parsing Strings into Numbers
Building Strings Efficiently
Bytes, Chars, and Grapheme Clusters
Try It Yourself
Regular Expressions
Try It Yourself
Raw String Literals
Ruby vs Rust: String Operations Cheat Sheet
Chapter Exercises
Summary
Chapter 9 Quiz
3 attempts allowed
Chapter 10: Lifetimes
Why Lifetimes Exist
Lifetime Annotation Syntax
Try It Yourself
When the Compiler Needs Lifetime Annotations
Lifetime Elision Rules
Try It Yourself
Lifetimes in Structs
Try It Yourself
Static Lifetime
Lifetime Annotations in Practice
Common Lifetime Patterns
Ruby vs Rust: Lifetimes are Not in Ruby
Chapter Exercises
Summary
Chapter 10 Quiz
3 attempts allowed
Chapter 11: Concurrency
Spawning Threads
Moving Data into Threads
Try It Yourself
Message Passing with Channels
Multiple Producers
Try It Yourself
Shared State with Arc and Mutex
Try It Yourself
Send and Sync — The Safety Traits
Try It Yourself
The Rayon Crate — Parallel Iterators
Try It Yourself
Concurrency Patterns: Ruby vs Rust
Choosing a Concurrency Approach
Chapter Exercises
Summary
Chapter 11 Quiz
3 attempts allowed
Chapter 12: Modules, Crates, and Testing
Packages and Crates
Try It Yourself
Modules — Organizing Code with mod
The Module File System Rules
Try It Yourself
Visibility with pub
Try It Yourself
use — Bringing Names into Scope
Try It Yourself
External Crates and Cargo.toml
Cargo Workspaces
Testing
Unit Tests (inline)
Assertion Macros
Integration Tests (in tests/ directory)
Test Organization
Try It Yourself
Common Project Layout
Ruby vs Rust: Project Structure Side by Side
Chapter Exercises
Summary
Chapter 12 Quiz
3 attempts allowed
Final Exam
Final Exam
2 attempts allowed
Appendix A: The Rust Toolchain
rustup — The Toolchain Manager
Cargo Commands Reference
Editor Setup
VS Code
Other Editors
Clippy — The Linter
rustfmt — The Formatter
Useful Crates by Category
Rust Documentation
CI Configuration (GitHub Actions)
Next Steps After This Book
Appendix B: Exercise Answers
Chapter 1
Chapter 2
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Glossary
Acknowledgements
Credits
From Ruby to Rust: The Course
Turn your Ruby instincts into safe, fast Rust: ownership, traits, lifetimes and more.
Learn Rust by mapping it to the Ruby you already write. Each chapter ends with a quiz, and a final exam earns you a certificate.
Minimum price
$149
$149
You pay
Author earns
About
About the Course
From Ruby to Rust
Turn your Ruby instincts into safe, fast Rust: ownership, traits, lifetimes and more.
What You'll Learn
✔ Set up the Rust toolchain
✔ Understand variables, types and mutability
✔ Model data with structs, impl blocks and enums
✔ Master ownership, borrowing and lifetimes
✔ Use collections and iterators
✔ Handle errors with Result
✔ Write generic code with traits
✔ Use concurrency, modules, crates and tests
Who Is This Course For?
Ruby developers who want to learn systems programming with Rust.
Prerequisites
Solid Ruby experience. No Rust experience needed.
Why This Course?
Rust's hardest ideas are explained against familiar Ruby code, so ownership and lifetimes make sense instead of feeling arbitrary.
How It Works
- 12 chapters, each ending with a 5-question multiple-choice quiz (3 attempts, best score counts)
- A 20-question final exam covering the whole course
- 80 quiz questions in total
- Score 70% to pass; 85% or more earns honors
- Pass to receive a certificate of completion
Written by Joel Bryan Juliano.
This course is included in this track...
Categories
Instructor
About the Instructor
Hi, I'm Joel.
I am Dutch-Filipino 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.
My journey has taken me through a variety of industries, from sports streaming to cybersecurity, both in the private sector and for the Dutch government, and everything in between.
Along the way, I’ve picked up a diverse set of skills and experiences, in which I document into books.
Material
Course Material
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.
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.)
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.
