Rust 语言学习手册

免费学习 系统级编程 内存安全

Rust学习手册《workspace 与 build.rs》:**工作空间(Workspace)** 管理多个 crate,共享编译产物。 ```toml [workspace] members = ["crate1", "crate2"] ``` **build.rs** 是构建脚本,在编译前运行...

Cargo 与工具链

workspace 与 build.rs

【详细说明 & 代码示例】
**工作空间(Workspace)** 管理多个 crate,共享编译产物。 ```toml [workspace] members = ["crate1", "crate2"] ``` **build.rs** 是构建脚本,在编译前运行,用于生成代码或链接库。 ```rust // build.rs fn main() { println!("cargo:rerun-if-changed=src/hello.c"); cc::Build::new().file("src/hello.c").compile("hello"); } ``` **条件编译** 使用 `cfg` 属性或 `cfg!` 宏。 ```rust #[cfg(target_os = "linux")] fn run() { /* linux */ } #[cfg(not(target_os = "linux"))] fn run() { /* other */ } ``` **常用环境变量** 在构建脚本中访问,如 `CARGO_MANIFEST_DIR`。

学习提示:建议安装 Rust 工具链(rustup),使用 cargo 构建项目,并熟悉 rustc 编译器错误信息(Rust 的报错非常详细友好)。

全部章节目录(共 63 个知识点)

Rust 基础 (1个知识点)

所有权系统 (1个知识点)

借用与引用 (1个知识点)

生命周期 (1个知识点)

Cargo 与工具链 (2个知识点)

使用说明

  • • 本手册涵盖 Rust 从基础到并发、异步、Web 开发的完整知识体系
  • • 在搜索框输入关键词,快速定位相关知识点
  • • 点击条目标题进入详情页,查看详细说明与代码示例
  • • 页面按分类展示所有知识点,方便系统性学习
  • • 建议通过 Rust 官方文档(doc.rust-lang.org)加深理解