下面给你一份从 0 到能写、能跑、能调试的 Linux + Rust 快速上手路线,偏实战、少废话。
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
验证:
rustc --version
cargo --version
rustup component add rust-analyzer
rustup component add clippy
rustup component add rustfmt
cargo new hello
cd hello
cargo run
目录结构:
src/main.rs
Cargo.toml
let s = String::from("hello");
let t = s; // s 失效
✅ Rust 没有 GC
✅ 编译期管内存
fn len(s: &String) -> usize {
s.len()
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}
match x {
0 => println!("zero"),
_ => println!("other"),
}
trait Speak {
fn speak(&self);
}
[dependencies]
clap = { version = "4", features = ["derive"] }
use std::fs;
use std::process;
[dependencies]
tokio = { version = "1", features = ["full"] }
axum = "0.7"
rust-gdb target/debug/hello
或:
cargo build
gdb ./target/debug/hello
cargo clippy
cargo fmt
| 天数 | 内容 |
|---|---|
| Day1 | 装环境 + cargo |
| Day2 | 基础语法 |
| Day3 | 所有权 & 借用 |
| Day4 | 文件 / 进程 |
| Day5 | CLI 工具 |
| Day6 | 错误处理 |
| Day7 | 小项目(如 ls 简化版) |
rust cli examples你可以直接说:
我可以按你的目标直接给代码和结构。