3
3
Cargo installs crates and fetches dependencies from a "registry". The default
4
4
registry is [ crates.io] . A registry contains an "index" which contains a
5
5
searchable list of available crates. A registry may also provide a web API to
6
- support publishing new crates directly from Cargo. The registry provides
7
- permanent access to all versions of a package that have been published to it.
6
+ support publishing new crates directly from Cargo.
8
7
9
8
> Note: If you are interested in mirroring or vendoring an existing registry,
10
9
> take a look at [ Source Replacement] .
11
10
12
11
### Using an Alternate Registry
13
12
14
- To use a registry other than [ crates.io] , the name and URL of the registry
15
- must be added to a [ ` .cargo/config ` file] [ config ] . The ` registries ` table
16
- has a key for each registry, for example:
13
+ To use a registry other than [ crates.io] , the name and index URL of the
14
+ registry must be added to a [ ` .cargo/config ` file] [ config ] . The ` registries `
15
+ table has a key for each registry, for example:
17
16
18
17
``` toml
19
18
[registries ]
20
19
my-registry = { index = " https://my-intranet:8080/git/index" }
21
20
```
22
21
23
22
The ` index ` key should be a URL to a git repository with the registry's index.
24
- Dependencies in a manifest can then refer to the name of the registry with the
25
- ` registry ` key to tell Cargo to fetch from that registry:
23
+ A crate can then depend on a crate from another registry by specifying the
24
+ ` registry ` key and a value of the registry's name in that dependency's entry
25
+ in ` Cargo.toml ` :
26
26
27
27
``` toml
28
28
# Sample Cargo.toml
@@ -42,7 +42,8 @@ environment variable will accomplish the same thing as defining a config file:
42
42
CARGO_REGISTRIES_MY_REGISTRY_INDEX=https://my-intranet:8080/git/index
43
43
```
44
44
45
- > Note: [ crates.io] does not accept packages that use other registries.
45
+ > Note: [ crates.io] does not accept packages that depend on crates from other
46
+ > registries.
46
47
47
48
### Publishing to an Alternate Registry
48
49
@@ -56,7 +57,7 @@ registry to use. For example, to publish the package in the current directory:
56
57
This only needs to be done once. You must enter the secret API token
57
58
retrieved from the registry's website. Alternatively the token may be
58
59
passed directly to the ` publish ` command with the ` --token ` command-line
59
- flag or and environment variable with the name of the registry such as
60
+ flag or an environment variable with the name of the registry such as
60
61
` CARGO_REGISTRIES_MY_REGISTRY_TOKEN ` .
61
62
62
63
2 . ` cargo publish --registry=my-registry `
@@ -65,7 +66,7 @@ Instead of always passing the `--registry` command-line option, the default
65
66
registry may be set in [ ` .cargo/config ` ] [ config ] with the ` registry.default `
66
67
key.
67
68
68
- Setting the ` package.publish ` key in ` Cargo.toml ` manifest restricts which
69
+ Setting the ` package.publish ` key in the ` Cargo.toml ` manifest restricts which
69
70
registries the package is allowed to be published to. This is useful to
70
71
prevent accidentally publishing a closed-source package to [ crates.io] . The
71
72
value may be a list of registry names, for example:
@@ -139,19 +140,27 @@ filename is the name of the package in lowercase. Each version of the package
139
140
has a separate line in the file. The files are organized in a tier of
140
141
directories:
141
142
142
- - Packages with 1 letter names are placed in a directory named ` 1 ` .
143
- - Packages with 2 letter names are placed in a directory named ` 2 ` .
144
- - Packages with 3 letter names are placed in the directory ` 3/{first-letter} `
145
- where ` {first-letter} ` is the first letter of the package name.
143
+ - Packages with 1 character names are placed in a directory named ` 1 ` .
144
+ - Packages with 2 character names are placed in a directory named ` 2 ` .
145
+ - Packages with 3 character names are placed in the directory
146
+ ` 3/{first-character} ` where ` {first-character} ` is the first character of
147
+ the package name.
146
148
- All other packages are stored in directories named
147
- ` {first-two}/{second-two} ` where the top directory is the first two letters
148
- of the package name, and the next subdirectory is the third and fourth
149
- letters of the package name. For example, ` cargo ` would be stored in a file
150
- named ` ca/rg/cargo ` .
149
+ ` {first-two}/{second-two} ` where the top directory is the first two
150
+ characters of the package name, and the next subdirectory is the third and
151
+ fourth characters of the package name. For example, ` cargo ` would be stored
152
+ in a file named ` ca/rg/cargo ` .
151
153
152
- > Note: Although the index filenames are in lowercase, the fields in
153
- > ` Cargo.toml ` manifests and the index JSON data are case-sensitive and may
154
- > contain upper and lower case characters.
154
+ > Note: Although the index filenames are in lowercase, the fields that contain
155
+ > package names in ` Cargo.toml ` and the index JSON data are case-sensitive and
156
+ > may contain upper and lower case characters.
157
+
158
+ Registries may want to consider enforcing limitations on package names added
159
+ to their index. Cargo itself allows names with any [ alphanumeric] , ` - ` , or ` _ `
160
+ character. For example, [ crates.io] imposes relatively strict limitations,
161
+ such as requiring it to be a valid Rust identifier, only allowing ASCII
162
+ characters, under a specific length, and rejects reserved names such as
163
+ Windows special filenames like "nul".
155
164
156
165
Each line in a package file contains a JSON object that describes a published
157
166
version of the package. The following is a pretty-printed example with comments
@@ -160,9 +169,11 @@ explaining the format of the entry.
160
169
``` javascript
161
170
{
162
171
// The name of the package.
163
- // This must contain alphanumeric, `-`, or `_` characters.
172
+ // This must only contain alphanumeric, `-`, or `_` characters.
164
173
" name" : " foo" ,
165
174
// The version of the package this row is describing.
175
+ // This must be a valid version number according to the Semantic
176
+ // Versioning 2.0.0 spec at https://semver.org/.
166
177
" vers" : " 0.1.0" ,
167
178
// Array of direct dependencies of the package.
168
179
" deps" : [
@@ -173,6 +184,8 @@ explaining the format of the entry.
173
184
// the `package` field.
174
185
" name" : " rand" ,
175
186
// The semver requirement for this dependency.
187
+ // This must be a valid version requirement defined at
188
+ // https://github.com/steveklabnik/semver#requirements.
176
189
" req" : " ^0.6" ,
177
190
// Array of features (as strings) enabled for this dependency.
178
191
" features" : [" i128_support" ],
@@ -218,13 +231,6 @@ explaining the format of the entry.
218
231
The JSON objects should not be modified after they are added except for the
219
232
` yanked ` field whose value may change at any time.
220
233
221
- Registries may want to consider enforcing limitations on package names added
222
- to their index. Cargo itself allows names with any [ alphanumeric] , ` - ` , or ` _ `
223
- character. For example, [ crates.io] imposes relatively strict limitations,
224
- such as requiring it to be a valid Rust identifier, only allowing ASCII
225
- characters, under a specific length, and rejects reserved names such as
226
- Windows special filenames like "nul".
227
-
228
234
### Web API
229
235
230
236
A registry may host a web API at the location defined in ` config.json ` to
@@ -286,7 +292,7 @@ The body of the data sent by Cargo is:
286
292
- 32-bit unsigned little-endian integer of the length of JSON data.
287
293
- Metadata of the package as a JSON object.
288
294
- 32-bit unsigned little-endian integer of the length of the ` .crate ` file.
289
- - The ` .crate ` fle .
295
+ - The ` .crate ` file .
290
296
291
297
The following is a commented example of the JSON object. Some notes of some
292
298
restrictions imposed by [ crates.io] are included only to illustrate some
@@ -526,7 +532,7 @@ A successful response includes the JSON object:
526
532
527
533
#### Search
528
534
529
- - Endpoint: ` /api/v1/crates/crates `
535
+ - Endpoint: ` /api/v1/crates `
530
536
- Method: GET
531
537
- Query Parameters:
532
538
- ` q ` : The search query string.
0 commit comments