Jump to ratings and reviews
Rate this book

Refactoring to Rust

Rate this book
Don’t rewrite from scratch! Improve your software speed and scalability by iteratively replacing performance-critical code with Rust Refactoring to Rust helps you get the speed and reliability of Rust libraries, functions, and high-performance features without needing a complete rewrite of your codebase. In Refactoring to Rust you will learn • 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 Rust is designed to gradually replace other languages by integrating and decomposing existing code. Refactoring to Rust helps you take full advantage of this amazing feature, even if you’ve never coded in Rust before. You’ll learn practical code-mixing techniques like embedding Rust libraries into apps written in other languages. About the technology Upgrade your software without starting from scratch! By incrementally introducing Rust into your codebase, you can upgrade key features and improve the performance of almost any application. This book shows you how to create standalone Rust libraries, boost speed and stability by using Rust for concurrency, and create safe, memory-efficient low-level code. About the book Refactoring to Rust shows you exactly where and how to integrate Rust surgically into applications written in another language. You’ll start by reviewing Rust’s unique syntax and concepts, with special emphasis on unique language features like variable lifetime and ownership. Then, you’ll learn to use Rust to wrap dangerous code, call standard and custom Rust libraries, and even use WASM to run Rust in the browser. What’s inside • Create Rust libraries you can call from other languages • Handle errors as values using Rust’s enums • Optimize for memory efficiency • Boost performance with Rust concurrency About the reader For intermediate programmers. No Rust experience required. About the author Lily Mara is a software engineer focused on high-performance Rust applications. Joel Holmes is a software developer building cloud native applications. He is the Author of Shipping Go, and Co-Author of Go in Action, Second Edition. Table of Contents 1 Why refactor to Rust 2 An overview of Rust 3 Introduction to C FFI and unsafe Rust 4 Advanced FFI 5 Structuring Rust libraries 6 Integrating with dynamic languages 7 Testing your Rust integrations 8 Asynchronous Python with Rust 9 WebAssembly for refactoring JavaScript 10 WebAssembly interface for refactoring

304 pages, Paperback

Published August 19, 2025

11 people want to read

About the author

Lily Mara

1 book

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
4 (80%)
4 stars
1 (20%)
3 stars
0 (0%)
2 stars
0 (0%)
1 star
0 (0%)
Displaying 1 - 5 of 5 reviews
2 reviews
August 20, 2025
As a developer tasked with maintaining an aging Elixir-based web infrastructure, I was constantly tweaking performance bottlenecks and scalability issues. Our once nimble app had grown sluggish under the weight of increased user demand and complex processing tasks. After reading "Refactoring to Rust", this book not only transformed our application but also reignited an excitement to revisit older apps, just to see what might be possible with this incredible language.

Refactoring to Rust hooked me with its promise of speed and reliability without starting from scratch. Something that several platforms offer but with their own caveats and gotchas. Our Elixir app, while robust (it's been running for over two years, now), struggled with some compute-heavy tasks, often taking seconds to process requests that should have been near-instantaneous. The authors’ clear, practical approach to integrating Rust’s high=performance capabilities into existing codebases felt like a lifeline. They make understanding Rust’s syntax simple, along with the ownership model, and borrowing system in a way that made sense to someone with zero Rust experience.

The book’s step-by-step guidance on using Rust’s Foreign Function Interface (FFI) to wrap performance-critical code was a revelation. We identified a key bottleneck in our app’s data processing pipeline, where parsing and transforming large datasets bogged down our servers. Following the authors’ advice, we rewrote just those functions in Rust, integrating them seamlessly via Elixir’s NIFs (Native Implemented Functions). The result was processing speeds improved by over 60%, slashing response times from 2.5 seconds to under a second. Our users noticed the difference immediately.

What sets this book apart is its focus on incremental refactoring. The authors understand the real-world constraints of legacy systems. Their techniques for structuring Rust libraries and handling errors as values using enums ensured our integrations were not only fast but also safe. Memory efficiency, a perennial concern in our Elixir app, improved dramatically thanks to Rust’s multiple string types and ownership model, which the book explains with easy-to-follow examples.

The chapters on testing Rust integrations gave me confidence that our changes wouldn’t introduce new bugs, while the WebAssembly section opened my eyes to future possibilities for browser-based performance tweaks. A future project, maybe.

Refactoring to Rust is a must-read for any developer stuck with a sluggish app or who simply want to learn a fast system using existing real-world code. I highly recommend it.
Profile Image for Leam Hall.
Author 7 books8 followers
September 1, 2025
Are you a Python, C/C++, or JavaScript/Wasm developer interested in Rust but currently maintaining thousands of lines of code in some other language? Do you wish there was a way to get the performance, concurrency, and memory safety of Rust into your current codebase?

Here's the book you need.

The authors score a quick win by writing with Fowler's "Refactoring" in mind. They continue the trend with clear language, giving good use cases for Rust, and explaining where refactoring to Rust might not be a win. After introducing the concepts of refactoring and benchmarking there's an overview of the Rust language. The rest of the book contains three major sections; the first deals with refactoring C/C++ to Rust, including the C FFI. There's a chapter on structuring Rust libraries and then you dive into integrating Python and Rust. Chapter 7 talks about testing Rust integrations natively and then with Python, and then Chapter 8 covers Asynchronous Python with Rust. The final two chapters explore Rust with JavaScript and WebAssembly.

The book lets you read the sections you need, but you're expected to have a moderate skill in the language(s) you're refactoring from. Familiarity with the C FFI is a win, but you don't have to be an expert.

I currently work in Python and enjoyed the step-by-step path provided. "Refactoring to Rust" introduces the paradigm and skills, then frees you to explore your passion.
2 reviews
August 28, 2025
This is a special Rust programming book, which is not a beginner's book, it's a book for intermediate to advanced readers. It is a book that guides developers in transitioning their code from other programming languages to Rust or interfacing there existing code from other programming languages to Rust. If you are in this situation, then this is the best and most suitable book for you.

This book advocates a gradual, surgical approach—identifying performance-critical or safety-sensitive parts of your code and incrementally replacing them with Rust modules that integrate seamlessly with the broader system.

My focus is FFI (Foreign Function Interfaces) part, this is the only book that explains so much about FFI. For example: how to wrap and safely integrate C or C++ code using Rust’s unsafe blocks and tools like bindgen and how to embed Rust into existing applications and embed Rust in Python...

If you are interested in FFI, or embed Rust into other technologies, then this is the book!

3 reviews
August 23, 2025
A hands-on guide to adopt Rust incrementally.

Refactoring to Rust is a guide for developers and teams looking to introduce Rust's safety and performance into an existing codebase without a complete rewrite.

The book is well written and breaks down complex topics. It doesn't just explain what makes Rust's memory model (ownership, lifetimes, the borrow checker) different; it shows why it's a game-changer for building robust software. The chapters are structured around practical, real-world refactoring patterns, each with well-explained code examples.

If you want to start benefiting from Rust's features by slowly and safely migrating parts of your project, this book is a valuable resource.
1 review
August 30, 2025
I haven't read all the chapters yet, but so far it has been really enjoyable. As someone who has finished the Rust Book, I found the part on FFI with C to be really informative for me, especially since the Rust Book doesn't delve a lot on how to do FFI with C.

The book really isn't for someone new to Rust, but more for people that have some experience with Rust. For people familiar with Rust, the book is easy to follow and has a wealth of information. For people interested in speeding up their applications by using a low-level language for hot paths in their code, the section on PyO3 is really good if you want a reference on Python-Rust interop.
Displaying 1 - 5 of 5 reviews

Can't find what you're looking for?

Get help and learn more about the design.