Get the speed and reliability of Rust libraries, functions, and high-performance features through incremental adoption without rewriting your codebase from scratch.
In Refactoring to Rust you will learn to:
Create Rust libraries you can call from other programming languages
Integrate Rust functions with code in other languages
Use Rust’s ownership and borrowing system to write high performance code
Handle errors as values using Rust’s enums
Minimize unnecessary memory usage with Rust’s multiple string types
Boost performance with Rust concurrency and async event processing
Create Rust HTTP services
Refactoring to Rust teaches you how to take advantage of Rust’s easy-to-use interoperating mechanisms. Learn practical code-mixing techniques like embedding Rust libraries into apps written in other languages. This practical guide emphasises techniques for incrementally refactoring performance-critical code to Rust while keeping the rest of your application in its original language.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
A practical guide to incrementally moving performance-critical code into Rust without rewriting your whole application, aimed at developers who already work in another language and want Rust's speed and safety in small, deployable steps.
【Book Arc】
- **Opening (~0%–10%)**: Frames refactoring as small-scale rewriting and argues why incremental replacement beats a full rewrite—continuous deployment, preserved production experience, and reusable tests.
- **Early (~10%–30%)**: Builds Rust fundamentals through the lens of a newcomer: ownership and moves, stack vs. heap, references and lifetimes, explicit mutability, and the String/&str split.
- **Middle (~30%–50%)**: Introduces enums as ordinary values, then uses them for error handling—Result, the unit type, custom error enums, and transforming overly generic errors into meaningful ones.
- **Late (~50%+)**: Moves toward integration and performance work: calling Rust from other languages, concurrency/async, and building Rust HTTP services (excerpts do not cover these chapters in detail).
- **Ending**: The book's stated endpoint is a refactored system where only the hot paths live in Rust while the rest of the application stays in its original language.
【Key Takeaways】
- **Refactoring is rewriting at a smaller scale** (Opening): Replace the smallest amount of code that fixes the biggest problem, so the system keeps serving users throughout the change.
- **Incremental deploys beat big-bang rewrites** (Opening): Small changes make it possible to attribute failures to a specific change, and existing tests can verify the refactored code honors the same contract.
- **Ownership is the central mental model** (Early): The compiler rejects use-after-move, and understanding stack vs. heap explains why values behave as they do.
- **Immutability is the default, mutability is opt-in** (Early): The `mut` keyword forces you to declare intent, and the compiler can then statically verify code that is hard to get right elsewhere.
- **Rust has multiple string types for a reason** (Early): `&str` is a cheap pointer-plus-length view; `String` is owned and allocating. Rule of thumb: `String` in long-lived structs, `&str` for read-only function parameters.
- **Errors are values, not exceptions** (Middle): `Result` and custom error enums let callers decide whether to retry, log, or abort—rather than unwinding the stack.
- **`unwrap()` is fine early, dangerous in production** (Middle): Panicking is acceptable during initialization or prototyping, but a web server should not crash because a request carried invalid data.
- **Rust is designed to interoperate** (Late): The payoff of the whole approach is embedding Rust libraries into apps written in other languages, not replacing them.
【Reading Tips】
- Read the opening chapter closely for the refactoring-vs-rewrite argument; it is the book's thesis and shapes every later decision.
- Treat the ownership, borrowing, and string chapters as the hard part—slow down there, and use the memory/lifetime diagrams rather than skimming past compiler errors.
- If you already know Rust basics, skim the fizz-buzz enum and error-handling walkthroughs and go straight to the interop, concurrency, and HTTP service material.
- Keep your own codebase in mind: after each chapter, identify one hot path you could move to Rust as a library call.
- Take away the planning discipline—the book stresses that planning dominates the refactoring process, so budget time for it before writing code.
【Coverage Limits】
The excerpts cover the book's framing, Rust fundamentals, and error handling in reasonable depth, but the later chapters on cross-language integration, concurrency/async, and HTTP services are only named, not detailed. This guide therefore describes those stages at a high level rather than summarizing their techniques.
Page 6
o find the parts of the system that are in need of the most help and replace the smallest amount of code possible to improve the system. The benefits of refa...
on enters our art museum, we want to welcome them by taking their name, and saying “Welcome {name}”. To do this, we’d need to first request that the computer...
five, print "fizzbuzz". Otherwise, print the number itself. We’re going to implement fizz buzz using one outer function to do the looping and printing, and a...
fn validate_unique(username: &str) -> Result<(), ()> And your validate_username function needs to have this signature and use this error type: enum UsernameE...
s? > 3 40 * 2 - 120 > 10 10 * 10 * 100 > 10 10 * hello! 100 Anything after the first three items will be ignored. Remember that we have been tasked with addi...
ve you from writing types over and over again. The instance.method() syntax is how we call a method on a specific instance of a type. Recall that the ? opera...
ing with other C functions. Next, we have read_body_handler. This is a callback function - it needs to be callable from C code, but the C code does not need...
s, there is a new method call that we have not seen before: let len = (*buf).last.offset_from(start) as usize; When constructing string slices from raw point...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
Refactoring to Rust MEAP V07 (Lily Mara, Joel Holmes)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
Refactoring to Rust MEAP V07 (Lily Mara, Joel Holmes)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment