mirror of https://github.com/rust-lang/book
Clarify meaning of crate. Fixes #3162.
This commit is contained in:
parent
78699a5cb5
commit
62bda19b89
|
@ -2,19 +2,25 @@
|
|||
|
||||
The first parts of the module system we’ll 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 we’ll 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 we’ve 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 we’ve
|
||||
created so far have been binary crates.
|
||||
|
||||
*Library crates* don’t have a `main` function, and they don’t 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 (we’ll explain modules in depth in the
|
||||
|
|
Loading…
Reference in New Issue