Clarify meaning of crate. Fixes #3162.

This commit is contained in:
Carol (Nichols || Goulding) 2022-05-20 21:46:18 -04:00
parent 78699a5cb5
commit 62bda19b89
No known key found for this signature in database
GPG Key ID: E907EE5A736F87D4
1 changed files with 16 additions and 10 deletions

View File

@ -2,19 +2,25 @@
The first parts of the module system well cover are packages and crates.
A *package* is one or more crates that provide a set of functionality. A
package contains a *Cargo.toml* file that describes how to build those crates.
A *crate* is the smallest amount of code that the Rust compiler considers at a
time. Even if you run `rustc` rather than `cargo` and pass a single source code
file (as we did all the way back in the “Writing and Running a Rust Program”
section of Chapter 1), the compiler considers that file to be a crate. Crates
can contain modules, and the modules may be defined in other files that get
compiled with the crate, as well see in the coming sections.
A *crate* can be a binary crate or a library crate. *Binary crates* are
programs you can compile to an executable that you can run, such as a
command-line program or a server. They must have a function called `main` that
defines what happens when the executable runs. All the crates weve created so
far have been binary crates.
A crate can come in one of two forms: a binary crate or a library crate.
*Binary crates* are programs you can compile to an executable that you can run,
such as a command-line program or a server. Each must have a function called
`main` that defines what happens when the executable runs. All the crates weve
created so far have been binary crates.
*Library crates* dont have a `main` function, and they dont compile to an
executable. They define functionality intended to be shared with multiple
projects. For example, the `rand` crate we used in [Chapter 2][rand]<!-- ignore
--> provides functionality that generates random numbers.
executable. Instead, they define functionality intended to be shared with
multiple projects. For example, the `rand` crate we used in [Chapter
2][rand]<!-- ignore --> provides functionality that generates random numbers.
Most of the time when Rustaceans say “crate”, they mean library crate, and they
use “crate” interchangably with the general programming concept of a “library".
The *crate root* is a source file that the Rust compiler starts from and makes
up the root module of your crate (well explain modules in depth in the