知识卡片
包管理多个编译单元
包由 Cargo.toml 描述,至少包含一个 crate,至多一个库 crate,并可有多个二进制 crate。crate 是编译单元,库供其他 crate 重用,二进制通过 main 启动。Cargo 按约定让 src/main.rs 和 src/lib.rs 分别充当两种默认的根,src/bin 可提供额外的二进制入口。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 用包、crate 和模块管理增长中的项目 Packages and Crates · 查看原书依据
Here, we have a package that only contains src/main.rs, meaning it only contains a binary crate named my-project. If a package contains src/main.rs and src/lib.rs, it has two crates: a binary and a library, both with the same name as the package. A package can have multiple binary crates by placing files in the src/bin directory: each file will be a separate binary crate.
参考来源
- 位置:《The Rust Programming Language(第2版)》第07章 用包、crate 和模块管理增长中的项目(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c07.xhtml`,块 0024)
- 结论依据:实际文件布局说明相同包内如何出现多个各有入口的 crate。
- 原始内容:Here, we have a package that only contains src/main.rs, meaning it only contains a binary crate named my-project. If a package contains src/main.rs and src/lib.rs, it has two crates: a binary and a library, both with the same name as the package. A package can have multiple binary crates by placing files in the src/bin directory: each file will be a separate binary crate.