Leanpub Header

Skip to main content

From C to Rust

Modernizing Production Systems Without Starting Over

From C to Rust
This book is 100% completeLast updated on 2026-08-25

Modernize your C codebase without tearing it apart. From C to Rust is a practical guide to introducing Rust where it actually makes sense, building safe boundaries and migrating piece by piece while production keeps running. No hype, no clean-slate fantasy, just real tradeoffs, runnable examples and a path you can follow.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
200
Pages
About

About

About the Book

This book is a practical, production-focused guide for engineers and organizations incrementally introducing Rust into mature C codebases. It shows how to evaluate existing systems, design safe interoperability boundaries, migrate components without destabilizing production behavior, and maintain working software throughout the transition. The emphasis is on engineering realism over hype: when Rust delivers real value, when it does not, what costs are involved, and exactly how to proceed step by step with complete, runnable examples at every stage.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 420 engineers and researchers. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

Modernizing Production Systems Without Starting Over

Introduction: Why Incremental Modernization Matters

Chapter 1: The Modernization Case

  1. What Production C Systems Actually Look Like Today
  2. Defect Patterns in Mature C Codebases
  3. The Safety Promise: Memory, Concurrency and Types
  4. Where Rust Gains Are Real and Measurable
  5. The Hidden Costs of Migration
  6. When Staying in C Is the Right Decision

Chapter 2: C and Rust Side by Side

  1. Compilation, Linking and the Object Model
  2. Primitive Types and Integer Semantics
  3. Pointers Versus References: What Actually Changes
  4. Structs, Unions, Enums and Data Layout
  5. Ownership, Moves and Copy Semantics
  6. Lifetimes and Borrowing for C Programmers
  7. Stack, Heap and Allocation Patterns
  8. RAII, Drop and Resource Management
  9. Mutability, Aliasing and Interior Mutability
  10. Error Handling: Return Codes Versus Result
  11. Generics, Traits and Pattern Matching
  12. Concurrency Primitives and Memory Ordering
  13. The Role and Meaning of unsafe

Chapter 3: Assessing Your C Codebase

  1. Inventorying Components and Dependencies
  2. Mapping Ownership Assumptions and Lifetime Contracts
  3. Locating Undefined Behavior and Memory Risks
  4. Measuring Test Coverage and Reliability Baselines
  5. Classifying Modules by Risk, Value and Complexity
  6. Identifying Migration Candidates: The Decision Matrix
  7. Building the Modernization Roadmap

Chapter 4: FFI Foundations: C and Rust Talking to Each Other

  1. The ABI Contract: extern “C” and Symbol Visibility
  2. Data Layout Compatibility with repr(C)
  3. Passing Primitives, Pointers and Arrays
  4. Strings Across the Boundary: CString and CStr
  5. Structs, Unions, Enums and Opaque Handles
  6. Function Pointers and Callbacks
  7. Ownership Transfer at FFI Boundaries
  8. Error Propagation Patterns
  9. Panic Handling and Unwinding Across Languages
  10. Thread Safety and Global State

Chapter 5: Build Systems and Tooling Integration

  1. Cargo in a Make and CMake World
  2. The cc Crate and Building C from Cargo
  3. Bindgen: Generating Bindings Automatically
  4. Build Scripts and pkg-config Integration
  5. Cross-Compilation and Target Triples
  6. Static Versus Dynamic Linking Strategies
  7. Reproducible Builds and Dependency Management

Chapter 6: Migration Pattern 1: Wrapping C Libraries Safely

  1. When Wrapping Is Better Than Rewriting
  2. Designing Opaque Handle Interfaces
  3. RAII Wrappers for Resource Handles
  4. Lifetime-Aware APIs Around Raw Pointers
  5. Validated Constructors and Error Types
  6. Encapsulating unsafe: The Safety Boundary Pattern
  7. Complete Example: Wrapping a C Configuration Parser

Chapter 7: Migration Pattern 2: Replacing Leaf Modules

  1. Identifying Replaceable Leaf Components
  2. Designing Drop-In Replacements via Stable ABIs
  3. Migrating String Utilities and Formatters
  4. Migrating Data Serialization Code
  5. Migrating Protocol Parsers
  6. Complete Example: Replacing a C Parser with Rust

Chapter 8: Migration Pattern 3: Strangler and Sidecar Approaches

  1. The Strangler Pattern for Long-Lived Systems
  2. Process Boundary Separation via IPC
  3. Sidecar Services in Rust
  4. Plugin Architectures with C-Compatible APIs
  5. Gradual Traffic Migration and Feature Flags
  6. Complete Example: Extracting a Subsystem Behind an API

Chapter 9: Creating Safe Abstractions Over Unsafe C APIs

  1. Newtypes and Domain-Specific Types
  2. Typestate Patterns for Stateful Resources
  3. Smart Pointer Wrappers for Ownership Tracking
  4. Synchronization Wrappers for Thread Safety
  5. Invariants and Encapsulated unsafe Blocks
  6. Writing Auditable Safety Comments
  7. Complete Example: Safe Wrapper Around a C Memory Pool

Chapter 10: Testing Behavioral Equivalence During Migration

  1. Characterization Tests for Legacy Systems
  2. Differential Testing of C and Rust Implementations
  3. Protocol Corpus and Golden Testing
  4. Fuzzing Mixed-Language Systems
  5. Concurrency and Stress Testing
  6. ABI Compatibility and Regression Testing
  7. Complete Example: Test Harness for Migrated Parser

Chapter 11: Performance Engineering and Verification

  1. Establishing Reproducible C Baselines
  2. Benchmarking Methodology and Pitfalls
  3. Comparing Latency, Throughput and Memory Use
  4. Allocation Behavior and Cache Performance
  5. When Rust Is Slower (and Why)
  6. Optimization Without Sacrificing Safety
  7. Complete Example: Before/After Performance Comparison

Chapter 12: Security Modernization and unsafe Governance

  1. Vulnerability Classes Rust Actually Prevents
  2. What Rust Does Not Fix Automatically
  3. Threat Modeling for Mixed-Language Systems
  4. Supply Chain Security and Dependency Governance
  5. Auditing and Reducing unsafe Code
  6. Organizational Policies for unsafe Review
  7. SBOM Generation and Reproducible Builds

Chapter 13: Concurrency Modernization

  1. Thread Safety Patterns in Mature C Code
  2. Send and Sync: What They Mean for C Interop
  3. Migrating Lock-Based Components
  4. Channels and Message Passing Patterns
  5. Atomics and Memory Ordering Across Languages
  6. Async Runtimes: When They Make Sense
  7. Complete Example: Migrating a Threading Component

Chapter 14: Deployment, Operations and Organizational Adoption

  1. Packaging Mixed-Language Applications
  2. Observability Across Language Boundaries
  3. Debugging Production Issues in C and Rust
  4. Crash Reporting and Core Dump Analysis
  5. Training C Engineers for Rust
  6. Code Review Practices for Mixed Systems
  7. Decision Frameworks: Migrate, Wrap, Rewrite, or Keep
  8. Common Failed Migration Approaches and Anti-Patterns
  9. Production Checklists

Chapter 15: Case Studies in Realistic Migration Scenarios

  1. Case Study 1: Migrating a Binary Protocol Parser
  2. Case Study 2: Wrapping a C Cryptographic Library
  3. Case Study 3: Migrating a Multithreaded Event Daemon
  4. Case Study 4: Embedded System Firmware Migration
  5. Case Study 5: Command-Line Utility Rewrite

Conclusion: A Roadmap for Evolving C Systems

References

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.

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