3
3
### Artifact
4
4
5
5
An * artifact* is the file or set of files created as a result of the
6
- compilation process. This includes linkable libraries and executable binaries.
6
+ compilation process. This includes linkable libraries, executable binaries,
7
+ and generated documentation.
8
+
9
+ ### Cargo
10
+
11
+ * Cargo* is the Rust [ * package manager* ] ( #package-manager ) , and the primary
12
+ topic of this book.
13
+
14
+ ### Cargo.lock
15
+
16
+ See [ * lock file* ] ( #lock-file ) .
17
+
18
+ ### Cargo.toml
19
+
20
+ See [ * manifest* ] ( #manifest ) .
7
21
8
22
### Crate
9
23
10
- Every target in a package is a * crate* . Crates are either libraries or
11
- executable binaries. It may loosely refer to either the source code of the
12
- target, or the compiled artifact that the target produces. A crate may also
13
- refer to a compressed package fetched from a registry.
24
+ A Rust * crate* is either a library or an executable program, referred to as
25
+ either a * library crate* or a * binary crate* , respectively.
26
+
27
+ Every [ target] ( #target ) defined for a Cargo [ package] ( #package ) is a * crate* .
28
+
29
+ Loosely, the term * crate* may refer to either the source code of the target or
30
+ to the compiled artifact that the target produces. It may also refer to a
31
+ compressed package fetched from a [ registry] ( #registry ) .
32
+
33
+ The source code for a given crate may be subdivided into [ * modules* ] ( #module ) .
14
34
15
35
### Edition
16
36
17
37
A * Rust edition* is a developmental landmark of the Rust language. The
18
38
[ edition of a package] [ edition-field ] is specified in the ` Cargo.toml `
19
- manifest, and individual targets can specify which edition they use. See the
20
- [ Edition Guide] for more information.
39
+ [ manifest] ( #manifest ) , and individual targets can specify which edition they
40
+ use. See the [ Edition Guide] for more information.
21
41
22
42
### Feature
23
43
24
44
The meaning of * feature* depends on the context:
25
45
26
46
- A [ * feature* ] [ feature ] is a named flag which allows for conditional
27
47
compilation. A feature can refer to an optional dependency, or an arbitrary
28
- name defined in a ` Cargo.toml ` manifest that can be checked within source
29
- code.
48
+ name defined in a ` Cargo.toml ` [ manifest] ( #manifest ) that can be checked
49
+ within source code.
30
50
31
51
- Cargo has [ * unstable feature flags* ] [ cargo-unstable ] which can be used to
32
52
enable experimental behavior of Cargo itself.
@@ -40,55 +60,107 @@ The meaning of *feature* depends on the context:
40
60
41
61
### Index
42
62
43
- The index is the searchable list of crates in a registry.
63
+ The * index* is the searchable list of [ * crates* ] ( #crate ) in a
64
+ [ * registry* ] ( #registry ) .
44
65
45
66
### Lock file
46
67
47
68
The ` Cargo.lock ` * lock file* is a file that captures the exact version of
48
- every dependency used in a workspace or package. It is automatically generated
49
- by Cargo. See [ Cargo.toml vs Cargo.lock] .
69
+ every dependency used in a [ * workspace* ] ( #workspace ) or
70
+ [ * package* ] ( #package ) . It is automatically generated by Cargo. See
71
+ [ Cargo.toml vs Cargo.lock] .
50
72
51
73
### Manifest
52
74
53
- A [ * manifest* ] [ manifest ] is a description of a package or a workspace in a
54
- file named ` Cargo.toml ` .
75
+ A [ * manifest* ] [ manifest ] is a description of a [ package] ( #package ) or a
76
+ [ workspace ] ( #workspace ) in a file named ` Cargo.toml ` .
55
77
56
78
A [ * virtual manifest* ] [ virtual ] is a ` Cargo.toml ` file that only describes a
57
79
workspace, and does not include a package.
58
80
59
81
### Member
60
82
61
- A * member* is a package that belongs to a workspace.
83
+ A * member* is a [ * package* ] ( #package ) that belongs to a
84
+ [ * workspace* ] ( #workspace ) .
85
+
86
+ ### Module
87
+
88
+ Rust's module system is used to organize code into logical units called
89
+ * modules* , which provide isolated namespaces within the code.
90
+
91
+ The source code for a given [ crate] ( #crate ) may be subdivided into one or more
92
+ separate modules. This is usually done to organize the code into areas of
93
+ related functionality or to control the visible scope (public/private) of
94
+ symbols within the source (structs, functions, and so on).
95
+
96
+ A [ ` Cargo.toml ` ] ( #manifest ) file is primarily concerned with the
97
+ [ package] ( #package ) it defines, its crates, and the packages of the crates on
98
+ which they depend. Nevertheless, you will see the term "module" often when
99
+ working with Rust, so you should understand its relationship to a given crate.
62
100
63
101
### Package
64
102
65
- A * package* is a collection of source files and a ` Cargo.toml ` manifest which
66
- describes the package. A package has a name and version which is used for
67
- specifying dependencies between packages. A package contains multiple targets,
68
- which are either libraries or executable binaries.
103
+ A * package* is a collection of source files and a ` Cargo.toml `
104
+ [ * manifest* ] ( #manifest ) file which describes the package. A package has a name
105
+ and version which is used for specifying dependencies between packages.
106
+
107
+ A package contains multiple [ * targets* ] ( #target ) , each of which is a
108
+ [ * crate* ] ( #crate ) . The ` Cargo.toml ` file describes the type of the crates
109
+ (binary or library) within the package, along with some metadata about each
110
+ one -- how each is to be built, what their direct dependencies are, etc., as
111
+ described throughout this book.
69
112
70
113
The * package root* is the directory where the package's ` Cargo.toml ` manifest
71
- is located.
114
+ is located. (Compare with [ * workspace root * ] ( #workspace ) .)
72
115
73
116
The [ * package ID specification* ] [ pkgid-spec ] , or * SPEC* , is a string used to
74
117
uniquely reference a specific version of a package from a specific source.
75
118
119
+ Small to medium sized Rust projects will only need a single package, though it
120
+ is common for them to have multiple crates.
121
+
122
+ Larger projects may involve multiple packages, in which case Cargo
123
+ [ * workspaces* ] ( #workspace ) can be used to manage common dependencies and other
124
+ related metadata between the packages.
125
+
126
+ ### Package manager
127
+
128
+ Broadly speaking, a * package manager* is a program (or collection of related
129
+ programs) in a software ecosystem that automates the process of obtaining,
130
+ installing, and upgrading artifacts. Within a programming language ecosystem,
131
+ a package manager is a developer-focused tool whose primary functionality is
132
+ to download library artifacts and their dependencies from some central
133
+ repository; this capability is often combined with the ability to perform
134
+ software builds (by invoking the language-specific compiler).
135
+
136
+ [ * Cargo* ] ( #cargo ) is the package manager within the Rust ecosystem. Cargo
137
+ downloads your Rust [ package] ( #package ) ’s dependencies
138
+ ([ * artifacts* ] ( #artifact ) known as [ * crates* ] ( #crate ) ), compiles your
139
+ packages, makes distributable packages, and (optionally) uploads them to
140
+ [ crates.io] [ ] , the Rust community’s [ * package registry* ] ( #registry ) .
141
+
142
+ ### Package registry
143
+
144
+ See [ * registry* ] ( #registry ) .
145
+
76
146
### Project
77
147
78
148
Another name for a [ package] ( #package ) .
79
149
80
150
### Registry
81
151
82
- A * registry* is a service that contains a collection of downloadable crates
83
- that can be installed or used as dependencies for a package. The default
84
- registry is [ crates.io] ( https://crates.io ) . The registry has an * index* which
152
+ A * registry* is a service that contains a collection of downloadable
153
+ [ * crates* ] ( #crate ) that can be installed or used as dependencies for a
154
+ [ * package* ] ( #package ) . The default registry in the Rust ecosystem is
155
+ [ crates.io] ( https://crates.io ) . The registry has an [ * index* ] ( #index ) which
85
156
contains a list of all crates, and tells Cargo how to download the crates that
86
157
are needed.
87
158
88
159
### Source
89
160
90
- A * source* is a provider that contains crates that may be included as
91
- dependencies for a package. There are several kinds of sources:
161
+ A * source* is a provider that contains [ * crates* ] ( #crate ) that may be included
162
+ as dependencies for a [ * package* ] ( #package ) . There are several kinds of
163
+ sources:
92
164
93
165
- ** Registry source** — See [ registry] ( #registry ) .
94
166
- ** Local registry source** — A set of crates stored as compressed files on
@@ -110,16 +182,17 @@ See [package ID specification](#package).
110
182
111
183
The meaning of the term * target* depends on the context:
112
184
113
- - ** Cargo Target** — Cargo packages consist of * targets* which correspond to
114
- artifacts that will be produced. Packages can have library, binary, example,
115
- test, and benchmark targets. The [ list of targets] [ targets ] are configured
116
- in the ` Cargo.toml ` manifest, often inferred automatically by the [ directory
185
+ - ** Cargo Target** — Cargo [ * packages* ] ( #package ) consist of * targets* which
186
+ correspond to [ * artifacts* ] ( #artifact ) that will be produced. Packages can
187
+ have library, binary, example, test, and benchmark targets. The
188
+ [ list of targets] [ targets ] are configured in the ` Cargo.toml `
189
+ [ * manifest* ] ( #manifest ) , often inferred automatically by the [ directory
117
190
layout] of the source files.
118
191
- ** Target Directory** — Cargo places all built artifacts and intermediate
119
192
files in the * target* directory. By default this is a directory named
120
- ` target ` at the workspace root, or the package root if not using a
121
- workspace. The directory may be changed with the ` --target-dir ` command-line
122
- option, the ` CARGO_TARGET_DIR ` [ environment variable] , or the
193
+ ` target ` at the [ * workspace* ] ( #workspace ) root, or the package root if not
194
+ using a workspace. The directory may be changed with the ` --target-dir `
195
+ command-line option, the ` CARGO_TARGET_DIR ` [ environment variable] , or the
123
196
` build.target-dir ` [ config option] .
124
197
- ** Target Architecture** — The OS and machine architecture for the built
125
198
artifacts are typically referred to as a * target* .
@@ -154,22 +227,24 @@ correctness of code. There are two types of test artifacts:
154
227
individual units of code.
155
228
* ** Integration test target** — An [ * integration test
156
229
target* ] [ integration-tests ] is an executable binary compiled from a * test
157
- target* which is a distinct crate whose source is located in the ` tests `
158
- directory or specified by the [ ` [[test]] ` table] [ targets ] in the
159
- ` Cargo.toml ` manifest. It is intended to only test the public API of a
160
- library, or execute a binary to verify its operation.
230
+ target* which is a distinct [ * crate* ] ( #crate ) whose source is located in the
231
+ ` tests ` directory or specified by the [ ` [[test]] ` table] [ targets ] in the
232
+ ` Cargo.toml ` [ * manifest* ] ( #manifest ) . It is intended to only test the public
233
+ API of a library, or execute a binary to verify its operation.
161
234
162
235
### Workspace
163
236
164
- A [ * workspace* ] [ workspace ] is a collection of one or more packages that share
165
- common dependency resolution (with a shared ` Cargo.lock ` ), output directory,
166
- and various settings such as profiles.
237
+ A [ * workspace* ] [ workspace ] is a collection of one or more
238
+ [ * packages* ] ( #package ) that share common dependency resolution (with a shared
239
+ ` Cargo.lock ` [ * lock file* ] ( #lock-file ) ), output directory, and various
240
+ settings such as profiles.
167
241
168
242
A [ * virtual workspace* ] [ virtual ] is a workspace where the root ` Cargo.toml `
169
- manifest does not define a package, and only lists the workspace members.
243
+ [ * manifest* ] ( #manifest ) does not define a package, and only lists the
244
+ workspace [ * members* ] ( #member ) .
170
245
171
246
The * workspace root* is the directory where the workspace's ` Cargo.toml `
172
- manifest is located.
247
+ manifest is located. (Compare with [ * package root * ] ( #package ) .)
173
248
174
249
175
250
[ Cargo.toml vs Cargo.lock ] : ../guide/cargo-toml-vs-cargo-lock.md
@@ -178,6 +253,7 @@ manifest is located.
178
253
[ Source Replacement ] : ../reference/source-replacement.md
179
254
[ cargo-unstable ] : ../reference/unstable.md
180
255
[ config option ] : ../reference/config.md
256
+ [ crates.io ] : https://crates.io/
181
257
[ directory layout ] : ../guide/project-layout.md
182
258
[ edition guide ] : ../../edition-guide/index.html
183
259
[ edition-field ] : ../reference/manifest.md#the-edition-field
0 commit comments