Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust for Java Programmers
Rust 面向 Java 程序员

AI-driven guide: Written with GPT-5.4 assistance for experienced Java developers who want to learn Rust with clear conceptual mapping and practical migration advice.
AI 驱动说明:本书由 GPT-5.4 协助撰写,面向已经有 Java 经验、希望系统学习 Rust 的开发者。

This book is a bridge text. It assumes comfort with Java, Maven or Gradle, the JVM, exceptions, interfaces, streams, and the usual enterprise toolkit. The goal is not to re-teach programming. The goal is to show which instincts transfer cleanly, which ones must change, and how to reach idiomatic Rust without dragging Java habits everywhere.
这本书定位成桥接教材。默认已经熟悉 Java、Maven 或 Gradle、JVM、异常、接口、Stream,以及常见企业开发工具。重点不是重复教授编程基础,而是说明哪些经验可以平移,哪些习惯必须调整,以及怎样走到更符合 Rust 社区习惯的写法。

Who This Book Is For
适合哪些读者

  • Developers who already write Java for backend services, tooling, data pipelines, or libraries
    已经用 Java 写后端服务、工具、数据处理程序或基础库的开发者。
  • Teams evaluating Rust for performance-sensitive or safety-sensitive components
    正在评估 Rust,用于性能敏感或安全敏感模块的团队。
  • Readers who want a chapter order that moves from syntax and ownership into async, FFI, and migration strategy
    希望按“语法与所有权 → async → FFI → 迁移策略”顺序系统推进的读者。

What You Will Learn
这本书会覆盖什么

  • How Rust differs from Java in memory management, error handling, type modeling, and concurrency
    Rust 在内存管理、错误处理、类型建模和并发方面与 Java 的核心差异。
  • How to map Java concepts such as interfaces, records, streams, Optional, and CompletableFuture into Rust equivalents
    如何把接口、record、Stream、OptionalCompletableFuture 这些 Java 经验映射到 Rust 世界。
  • How to structure real Rust projects with Cargo, crates, modules, testing, and common ecosystem tools
    如何使用 Cargo、crate、模块、测试和常见生态工具来组织真实 Rust 项目。
  • How to migrate gradually instead of attempting a reckless full rewrite
    如何渐进式迁移,而不是头脑发热搞一次性重写。

Suggested Reading Order
建议阅读顺序

Range
范围
Focus
重点
Outcome
阶段结果
Chapters 1-4
第 1-4 章
Motivation, setup, core syntax
动机、环境、基础语法
Can read and write small Rust programs
能够读写小型 Rust 程序。
Chapters 5-7
第 5-7 章
Data modeling and ownership
数据建模与所有权
Can explain moves, borrows, and Option
能够讲清 move、borrow 和 Option
Chapters 8-10
第 8-10 章
Project structure, errors, traits
工程结构、错误、trait
Can organize multi-file crates and design APIs
能够组织多文件 crate 并设计基础 API。
Chapters 11-14
第 11-14 章
Conversions, iterators, async, FFI, testing
转换、迭代器、async、FFI、测试
Can build realistic services and tools
能够开始写接近真实项目的工具和服务。
Chapters 15-17
第 15-17 章
Migration, tooling, capstone
迁移、工具链、综合项目
Can plan a Java-to-Rust adoption path
能够设计一条从 Java 过渡到 Rust 的采用方案。

Companion Books In This Repository
仓库里的配套教材

Table of Contents
目录

Part I — Foundations
第一部分:基础

Part II — Concurrency and Systems
第二部分:并发与系统

Part III — Migration and Practice
第三部分:迁移与实践

Capstone
综合项目