# Rust — Memory-Safe Systems Programming Language > Rust is a systems programming language focused on safety, speed, and concurrency. Memory safety without garbage collection via its ownership model. Powers Firefox, Cloudflare, Discord, AWS Firecracker, and a growing share of core infrastructure. ## Install Save in your project root: ## Quick Use ```bash # Install via rustup curl --proto =https --tlsv1.2 -sSf https://sh.rustup.rs | sh source ~/.cargo/env rustc --version cargo --version ``` Hello world: ```rust // src/main.rs use std::collections::HashMap; fn main() { let mut counts = HashMap::new(); for word in "hello world hello rust".split_whitespace() { *counts.entry(word).or_insert(0) += 1; } for (word, count) in &counts { println!("{word}: {count}"); } } ``` Cargo commands: ```bash cargo new my_project --bin cd my_project cargo run cargo build --release cargo test cargo clippy # Lint cargo fmt # Format cargo add serde --features derive cargo publish cargo install ripgrep # Install global tool ``` ## Intro Rust is a systems programming language focused on safety, speed, and concurrency. It guarantees memory safety without using garbage collection, thanks to a unique ownership and borrowing model enforced at compile time. Originally designed by Graydon Hoare at Mozilla starting 2006, now governed by the Rust Foundation. Powers Firefox, Cloudflare Workers, Discord backend, AWS Firecracker, and a growing share of critical infrastructure. - **Repo**: https://github.com/rust-lang/rust - **Stars**: 111K+ - **License**: Apache 2.0 + MIT (dual) ## 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 --- Source: https://tokrepo.com/en/workflows/1b74899e-35fe-11f1-9bc6-00163e2b0d79 Author: AI Open Source