Keywords: ownership, error handling, collections, tooling, playbook, macros, production hygiene
อ่านแบบคน Python:
- ถ้าอยากเอา “ภาพรวม” ก่อน: อ่านโหมด A/B/C แล้วเลือกเส้นทาง
- ถ้าอยาก “ลงมือทำ”: เปิด
01-start-basic.mdแล้วไล่ต่อด้วย Prev/Next - ถ้าติดระหว่างทาง: เปิด 12-learning-playbook.md
ชุดเอกสารนี้เน้น “เรียน Rust จากวิธีคิด Python” โดยยึดตัวอย่างเปรียบเทียบ Python ↔ Rust เป็นหลัก
สิ่งที่ตั้งใจให้คุณได้ (แบบเอาไปใช้ได้จริง):
- ออกแบบโปรแกรมแบบ Rust ได้: owner/borrow/error path ชัด
- อ่าน compiler error แล้วแก้ได้เป็นขั้นตอน (ไม่เดา)
- แปลง data model จาก dict/list ไปเป็น struct/Vec/HashMap แบบไม่ปวด
- วางโครงโปรเจกต์ + workflow ให้ทำงานจริงได้ (
cargo check/fmt/clippy/test)
อ่านตามลำดับเลขไฟล์ (00 → 18) จะต่อเนื่องที่สุด เพราะบทถูกเรียงตาม “ลำดับที่สมองคนมาจาก Python มักสะดุด”
ถ้าอยากอ่านแบบมีเป้าหมาย ให้ใช้ 3 โหมดนี้:
01-start-basic.md02-ownership-and-borrowing.md03-error-handling.md04-collections-and-data-modeling.md
เหตุผล: 4 บทนี้คือแกนที่ทำให้คุณ “คุมข้อมูล + คุม error + คุมรูปทรงข้อมูล” ได้ก่อน แล้วค่อยต่อยอด
05-modules-project-structure.md06-tooling-and-workflow.md10-cli-basics.md09-config-and-serde-json.md
เหตุผล: ได้โครงโปรเจกต์ + วงจรพัฒนา + CLI + config ซึ่งเป็นสนามฝึกที่ปลอดภัยและใกล้งานจริง
12-learning-playbook.md— เปิดทันทีเมื่อเจอ borrow checker/compile error แล้วไม่รู้เริ่มตรงไหน11-mini-projects.md— ฝึกแบบ “หนึ่งโปรเจกต์ = หนึ่ง crate” เพื่อให้ลองเต็มที่และไม่พังของเดิม
Output (example)คือ output ตัวอย่างเพื่อให้เห็นภาพ (ของจริงอาจต่างเล็กน้อยตาม environment/เวอร์ชัน)(no output — ...)หมายถึง snippet นั้นเป็นแค่การประกาศ/นิยาม/assign ยังไม่ได้รัน logic ที่พิมพ์อะไรแนวคิด:คือข้อสรุปเชิงความเข้าใจเพื่อให้เห็นภาพรวมแนวทาง:คือข้อแนะนำเชิงปฏิบัติเพื่อช่วยตัดสินใจเร็ว — ไม่ใช่กฎตายตัว 100%
- 01-start-basic.md — setup, hello world, variables, ownership intro, Option/Result, enum/match, serde_json intro
- 02-ownership-and-borrowing.md — ownership/borrowing ให้แตกฉาน + pattern ที่เจอบ่อย
- 03-error-handling.md — Option/Result,
?, error types, logging errors - 04-collections-and-data-modeling.md — dict/list → HashMap/Vec/struct, serde modeling
- 05-modules-project-structure.md — จาก monolith → mod/crate, layout ที่ดูแลง่าย
- 06-tooling-and-workflow.md — cargo, fmt, clippy, test, doc
- 07-shared-state-and-concurrency.md — global state → AppState + Arc/Mutex/RwLock (conceptual)
- 08-logging-design.md — จาก override
print()→ log pipeline ที่แยก concerns - 09-config-and-serde-json.md — อ่าน JSON แบบค่อย ๆ tighten schema (Value → typed struct → strict)
- 10-cli-basics.md — ทำ CLI แบบ Rust: parse → command enum → execute
- 11-mini-projects.md — mini exercises ที่ตั้งใจให้ปลอดภัย (local/offline)
- 12-learning-playbook.md — playbook การเรียนต่อ + เช็กลิสต์เวลาเจอ borrow checker
- 13-lifetimes-practical.md — lifetimes แบบใช้จริง (ไม่ใช่ทฤษฎีล้วน)
- 14-traits-and-generics.md — จาก duck typing → trait bounds + generics
- 15-iterators-and-closures.md — map/filter/collect, closures,
moveใน closure - 16-testing-and-debugging.md — test structure, assert, debug workflow
- 17-serde-advanced.md — serde ขั้นสูง: default/rename/deny_unknown_fields + validation
- 18-rust-macros.md — Rust macros แบบเข้าใจง่าย:
println!,vec!,format!, และภาพรวมการ expand - 19-production-hygiene.md — production hygiene: deps/secrets/config/logs/lifecycle
ใช้เป็น “คีย์เวิร์ดนำทาง” ข้ามบท: กดคำแล้วกระโดดไปบทที่อธิบายเรื่องนั้นเป็นหลัก
- ownership — owner / move / drop
- borrowing —
&T/&mut T - lifetimes — ความสัมพันธ์ของ reference
- macros —
println!,vec!,format!,macro_rules!
- error handling —
Option,Result,? - testing —
cargo test,assert_*, debug workflow
- collections —
Vec,HashMap, struct modeling - config — I/O → JSON → schema → semantics
- serde — default/rename/strictness (
deny_unknown_fields)
- modules — crate/mod, lib+bin boundary
- tooling —
cargo check/fmt/clippy/test - CLI — args → command enum → execute
- concurrency —
Arc,Mutex,RwLock, background tasks & lifecycle - logging — event → formatter → sink, context (
request_id/job_id)
- atomic writes — write tmp + rename, schema versioning
- traits — trait/impl,
dyn Trait, bounds - generics — type params, bounds
- iterators —
iter/map/filter/collect - closures — closures,
moveclosure
- TRPL: https://doc.rust-lang.org/book/
- Ownership chapter: https://doc.rust-lang.org/book/ch04-00-understanding-ownership.html
- std::sync:
Arc,Mutex,RwLock - serde_json: https://docs.rs/serde_json