Learning Path and Next Steps
学习路径与下一步
What you’ll learn: A structured Rust learning plan tailored for experienced Java developers, the concept pairs that matter most during migration, and a resource stack that supports moving from language study to real service work.
本章将学习: 一套面向已有 Java 经验开发者的 Rust 学习路线,迁移过程中最重要的概念映射,以及从语言学习走向真实服务开发时该依赖的资源组合。Difficulty: 🟢 Beginner
难度: 🟢 入门
The fastest way for a Java developer to learn Rust is to map familiar Java concepts to Rust concepts in the right order.
Java 开发者学习 Rust 最快的方式,不是从零散知识点乱看,而是把熟悉的 Java 概念按正确顺序映射到 Rust 概念上。
The Six Concept Pairs That Matter Most
最关键的六组概念映射
| Java habit Java 习惯 | Rust replacement Rust 对应物 |
|---|---|
null and Optional<T>null 与 Optional<T> | Option<T> |
| exceptions 异常 | Result<T, E> |
| mutable object references 可变对象引用 | ownership and borrowing 所有权与借用 |
| interfaces 接口 | traits |
| class hierarchies 类继承层级 | struct + enum + compositionstruct、enum、组合 |
| Spring container wiring Spring 容器装配 | explicit state and constructors 显式状态与构造 |
If these six pairs feel natural, most later Rust topics become easier.
如果这六组映射真的顺手了,后面大多数 Rust 主题都会轻松很多。
An 8-Week Plan
一个 8 周学习计划
Weeks 1-2
第 1 到 2 周
Stringvs&str
搞清楚String和&str。- move vs borrow
搞清楚移动和借用。 Option<T>andResult<T, E>
掌握Option<T>与Result<T, E>。
Weeks 3-4
第 3 到 4 周
enumandmatch
重点学enum和match。- traits as interface-like behavior
把 trait 理解成接口式行为抽象。 Vec,HashMap, iterators
掌握Vec、HashMap、迭代器。
Weeks 5-6
第 5 到 6 周
- crate-level error enums
crate 级错误枚举。 thiserrorandanyhowthiserror与anyhow的分工。tokioand async basicstokio和异步基础。
Weeks 7-8
第 7 到 8 周
axumoractix-webaxum或actix-web。- configuration, tracing, metrics
配置、追踪、指标。 - handler/service/repository boundaries
handler、service、repository 的边界划分。
Suggested Project Ladder
建议的项目阶梯
- log or CSV transformation tool
日志或 CSV 转换工具。 - JSON validation job
JSON 校验任务。 - external API client
外部 API 客户端。 - small HTTP service
一个小型 HTTP 服务。 - Spring Boot endpoint migration
迁移一个 Spring Boot 接口。
This ordering matters because jumping into async web services too early usually mixes framework confusion with ownership confusion.
这个顺序非常重要,因为过早跳进异步 Web 服务,往往会把框架困惑和所有权困惑混成一锅粥。
Resource Stack
资源组合
- The Rust Programming Language
官方 Rust 书,最核心。 - Rust by Example
适合快速看小例子。 - Rustlings
适合形成基本手感。 serdedocs
做 JSON 和数据模型时非常重要。tokiotutorial
理解异步运行时的最好起点之一。axumguide
做 Web 服务时非常贴近实战。
Common Traps
常见陷阱
Trap 1: Treating the Borrow Checker as the Enemy
误区一:把借用检查器当成敌人
The borrow checker is exposing aliasing and mutation truth, not randomly blocking progress.
借用检查器是在揭示别名与可变性的真实约束,不是在随机刁难人。
Trap 2: Recreating Inheritance Everywhere
误区二:到处重建继承体系
If a closed set of cases is modeled with traits only, an enum is often missing.
如果一个封闭变体集合全靠 trait 去建模,那往往说明 enum 该出现却没出现。
Trap 3: Learning Async Before Ownership
误区三:还没懂所有权就急着学异步
Async Rust is much easier after ownership, moves, and Result already feel normal.
只有当所有权、移动、Result 这些基础已经顺手了,Async Rust 才会真正容易起来。
Ready-for-Real-Work Milestone
进入真实迁移工作的里程碑
- can model domain states with
enum
能用enum建模领域状态。 - can explain ownership and borrowing clearly
能把所有权和借用讲明白。 - can define crate-level error types
能设计 crate 级错误类型。 - can build a small HTTP service with shared state
能写带共享状态的小型 HTTP 服务。 - can compare a Spring Boot endpoint with its Rust equivalent
能把一个 Spring Boot 接口和它的 Rust 对应物讲清差异。