Tooling, Testing & Deployment
เครื่องมือเดียวครบจบ
หัวข้อที่มีชื่อว่า “เครื่องมือเดียวครบจบ”ใน Node.js คุณต้องประกอบ toolchain เองทั้งหมด: npm (หรือ yarn/pnpm) สำหรับ packages, tsc สำหรับ compile, eslint สำหรับ lint, prettier สำหรับ format, jest/vitest สำหรับ test และ esbuild/webpack/rollup สำหรับ bundle แต่ละตัวมี config file ของตัวเอง, CLI flags ของตัวเอง และ plugin ecosystem ของตัวเอง
Rust มาพร้อมเครื่องมือทางการเพียงตัวเดียวคือ Cargo ซึ่งจัดการงานทั้งหมดเหล่านั้น:
| งานใน Node / TS | เทียบเท่าใน Cargo |
|---|---|
npm install | cargo add / cargo fetch |
tsc | cargo build |
node index.js | cargo run |
eslint | cargo clippy |
prettier | cargo fmt |
jest | cargo test |
npm publish | cargo publish |
npx tsdoc | cargo doc |
ไม่มีการ “เลือกเอง” community Rust ใช้ formatter เดียว (rustfmt), linter เดียว (Clippy) และ test runner เดียว ทำให้ทุก Rust project มีหน้าตาคุ้นเคย
สิ่งที่คุณจะเรียนในโมดูลนี้
หัวข้อที่มีชื่อว่า “สิ่งที่คุณจะเรียนในโมดูลนี้”- cargo.mdx — manifest
Cargo.toml,Cargo.lockและ subcommand ที่สำคัญ - clippy-rustfmt.mdx — lint ด้วย Clippy และ format ด้วย rustfmt เทียบกับ eslint + prettier
- testing.mdx — unit test ด้วย
#[test], integration test และ doctest เทียบกับ Jest - workspaces-features.mdx — workspace หลาย crate และ feature flag เทียบกับ npm workspaces
- release-cross-compile.mdx — release build และ cross-compilation ไปยัง static binary
- docker-ci.mdx — multi-stage Dockerfile และ GitHub Actions สำหรับ Rust project
เปรียบเทียบ: เริ่มต้น project
หัวข้อที่มีชื่อว่า “เปรียบเทียบ: เริ่มต้น project”# Node / TypeScriptnpm init -ynpm install typescript --save-devnpx tsc --init# Now you also need eslint, prettier, jest...# Rustcargo new my-appcd my-appcargo build # compilescargo run # compiles + runscargo test # runs all testscargo clippy # lintscargo fmt # formatsนี่คือบทภาพรวมของโมดูล ไม่มี Playground ในบทนี้ — บทถัดไปแต่ละบทจะสาธิต tool เฉพาะ รัน Cargo command ข้างต้นใน terminal ของคุณหลังจากติดตั้ง Rust ผ่าน rustup.rs