What Rust Does
- Ownership system — each value has a single owner, borrowed references checked at compile time
- Zero-cost abstractions — high-level code compiles to optimal low-level output
- No null, no exceptions — Option and Result types for absent/error values
- Pattern matching — exhaustive match expressions
- Trait system — structural polymorphism
- Fearless concurrency — data races prevented by borrow checker
- Cargo — package manager and build tool built in
- WebAssembly — first-class compilation target
- Async/await — since Rust 1.39
Architecture
Compiler (rustc) built on LLVM backend. Uses MIR (Mid-level Intermediate Representation) for borrow checking, then LLVM IR for optimization. Cargo manages dependencies from crates.io, the community package registry. Language evolves through an RFC process.
Self-Hosting
Language toolchain.
Key Features
- Memory safety without GC
- Zero-cost abstractions
- Ownership + borrowing
- Pattern matching
- Trait-based generics
- Cargo build system
- crates.io package registry
- Async/await support
- WebAssembly target
- Excellent tooling (clippy, rustfmt, rust-analyzer)
Comparison
| Language | Memory Safety | Runtime | Bundle Size |
|---|---|---|---|
| Rust | Compile-time (ownership) | No GC | Small |
| C | Manual | None | Smallest |
| C++ | Manual + RAII | None | Small |
| Go | Runtime (GC) | GC | Medium |
| Swift | ARC (ref counting) | Small | Medium |
| Zig | Manual (+ tools) | None | Small |
常见问题 FAQ
Q: 学习曲线有多陡? A: 第一两周挑战 borrow checker(学习掌握 ownership 和生命周期)。熟悉后生产力很高。Rust 编译器错误信息是业界最好之一。
Q: 何时选 Rust? A: 系统编程、性能敏感的 CLI 工具(ripgrep、bat、fd)、WebAssembly、区块链、嵌入式、游戏引擎、数据库引擎。
Q: 编译速度慢? A: 是 Rust 的痛点。应对:增量编译、cargo check(快速类型检查)、sccache 缓存、分 workspace。v1.x 持续优化中。
来源与致谢 Sources
- Docs: https://www.rust-lang.org/learn
- GitHub: https://github.com/rust-lang/rust
- License: Apache 2.0 + MIT