1. なぜ錆びるのか?
| 基準 | さび | 行く | C++ |
|---|---|---|---|
| メモリの安全性 | コンパイル時 (借用チェッカー) | GC | マニュアル |
| パフォーマンス | 水平C/C++ | 良好 (GC 一時停止) | 最高 |
| 同時実行性 | 恐れを知らない同時実行性 | ゴルーチン | スレッド + ロック |
| コストゼロの抽象化 | ✅ | ❌ | ✅ |
| ヌルセーフティ | オプション | なし | nullptr |
2.Rustをインストールする
# Cài rustup (Rust toolchain manager)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Verify
rustc --version
cargo --version
# Update
rustup update
# Components hữu ích
rustup component add clippy # Linter
rustup component add rustfmt # Formatter
3. Cargo — パッケージマネージャーおよびビルドツール
# Tạo project mới
cargo new my-app
cd my-app
# Cấu trúc project
# my-app/
# ├── Cargo.toml # Manifest (giống package.json)
# ├── src/
# │ └── main.rs # Entry point
# Cargo.toml
[package]
name = "my-app"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1", features = ["full"] }
4. ハローワールド
fn main() {
let name = "Rust";
println!("Hello, {}!", name);
// Formatted printing
println!("Decimal: {}", 42);
println!("Binary: {:b}", 42);
println!("Debug: {:?}", vec![1, 2, 3]);
println!("Pretty: {:#?}", vec![1, 2, 3]);
}
# Build & Run
cargo run
# Build release
cargo build --release
# Check (compile without codegen — nhanh hơn)
cargo check
# Format code
cargo fmt
# Lint
cargo clippy
次の記事: 変数、型、制御フロー。