Cargo 生态系统中的 'crate' 到底是什么,与 crates.io 上的内容的映射是什么?

What exactly is a 'crate' in the Cargo ecosystem and what is the mapping to what is on crates.io?

我对 crates.io 上托管的确切内容有点困惑('crate' 是指代这些内容的正确方式吗)?我的理解是 crate 是 Rust 中的一个编译单元,但是 crates 和 crates.io 上的内容之间的映射是什么?例如,The Rust Programming Language appendix on macros 表示由于每个 crate 只能有一个程序宏:

Our two crates are tightly related, so we create the procedural macro crate within the directory of our hello_macro crate. If we change the trait definition in hello_macro, we’ll have to change the implementation of the procedural macro in hello_macro_derive as well. The two crates will need to be published separately, and programmers using these crates will need to add both as dependencies and bring them both into scope. We could instead have the hello_macro crate use hello_macro_derive as a dependency and reexport the procedural macro code. But the way we’ve structured the project makes it possible for programmers to use hello_macro even if they don’t want the derive functionality.

它必须在 crates.io 上单独发布。这看起来很清楚:crates.io 上的 crate 与本地 crate 相同,并且映射是一对一的。

但是,在讨论包含可执行文件和库的项目时,这意味着它们是单独的 crate,但不需要单独发布。例如,sccache 存储库同时具有 main.rs 和 lib.rs。单独的二进制箱子实际上没有存储在 crates.io 上并且只驻留在回购中吗?那么 cargo install 如何确定要安装什么?

什么是 "package"?

我尝试 运行 cargo package 使用包含二进制和库目标的示例项目。并且 both 都被添加到 .cargo 文件中(顺便说一句,.cargo 档案的确切格式是否记录在 anywhere?)。这仍然让我感到困惑。我们可以将多个箱子作为一个包的一部分发布吗?我们是否应该将存储在 crates.io 上的内容称为 packages?我是否可以假设每个包可以包含多个二进制包但只有一个库包?这是我目前的理解。

托管在 crates.io 上的确切内容是包裹内的板条箱。

一个crate是编译器的输出神器。

来自Rust Reference Manual

The compilation model centers on artifacts called crates. Each compilation processes a single crate in source form, and if successful, produces a single crate in binary form: either an executable or some sort of library.

A package 是由 Rust 包管理器 Cargo 管理的工件。

Cargo.toml 清单文件使用以下语法定义包:

[package]
name = "hello_world"
version = "0.1.0"
authors = ["Your Name <you@example.com>"]  

一个包可能包含一个或多个包装箱,例如一个库包装箱,命名为包名称和零个或多个可执行包装箱,每个包装箱在 [[bin]] 清单文件的部分,或者如果位于包的 src/bin 目录中则隐含。

Cargo book 使用术语 crate 作为包的别名。考虑以下语句以尝试了解一些意义:

通常*一个包的主要工件是一个库 crate,因为它是用包名来标识的,所以习惯上将 package 和 crate 视为同义词。

*:一个包可能只包含一个二进制文件,例如 ripgrep