From 62bda19b89d2c5ca3242c98fd6eae887edbf20ff Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Fri, 20 May 2022 21:46:18 -0400 Subject: [PATCH] Clarify meaning of crate. Fixes #3162. --- src/ch07-01-packages-and-crates.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/ch07-01-packages-and-crates.md b/src/ch07-01-packages-and-crates.md index 6872e698a..add89ed57 100644 --- a/src/ch07-01-packages-and-crates.md +++ b/src/ch07-01-packages-and-crates.md @@ -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] 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] 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