Skip to content

Commit 8b27a7b

Browse files
committed
Update for review comments.
1 parent 3229b01 commit 8b27a7b

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

src/doc/src/reference/registries.md

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
Cargo installs crates and fetches dependencies from a "registry". The default
44
registry is [crates.io]. A registry contains an "index" which contains a
55
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.
87

98
> Note: If you are interested in mirroring or vendoring an existing registry,
109
> take a look at [Source Replacement].
1110
1211
### Using an Alternate Registry
1312

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:
1716

1817
```toml
1918
[registries]
2019
my-registry = { index = "https://my-intranet:8080/git/index" }
2120
```
2221

2322
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`:
2626

2727
```toml
2828
# Sample Cargo.toml
@@ -42,7 +42,8 @@ environment variable will accomplish the same thing as defining a config file:
4242
CARGO_REGISTRIES_MY_REGISTRY_INDEX=https://my-intranet:8080/git/index
4343
```
4444

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.
4647
4748
### Publishing to an Alternate Registry
4849

@@ -56,7 +57,7 @@ registry to use. For example, to publish the package in the current directory:
5657
This only needs to be done once. You must enter the secret API token
5758
retrieved from the registry's website. Alternatively the token may be
5859
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
6061
`CARGO_REGISTRIES_MY_REGISTRY_TOKEN`.
6162

6263
2. `cargo publish --registry=my-registry`
@@ -65,7 +66,7 @@ Instead of always passing the `--registry` command-line option, the default
6566
registry may be set in [`.cargo/config`][config] with the `registry.default`
6667
key.
6768

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
6970
registries the package is allowed to be published to. This is useful to
7071
prevent accidentally publishing a closed-source package to [crates.io]. The
7172
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
139140
has a separate line in the file. The files are organized in a tier of
140141
directories:
141142

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.
146148
- 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`.
151153

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".
155164

156165
Each line in a package file contains a JSON object that describes a published
157166
version of the package. The following is a pretty-printed example with comments
@@ -160,9 +169,11 @@ explaining the format of the entry.
160169
```javascript
161170
{
162171
// The name of the package.
163-
// This must contain alphanumeric, `-`, or `_` characters.
172+
// This must only contain alphanumeric, `-`, or `_` characters.
164173
"name": "foo",
165174
// 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/.
166177
"vers": "0.1.0",
167178
// Array of direct dependencies of the package.
168179
"deps": [
@@ -173,6 +184,8 @@ explaining the format of the entry.
173184
// the `package` field.
174185
"name": "rand",
175186
// The semver requirement for this dependency.
187+
// This must be a valid version requirement defined at
188+
// https://github.com/steveklabnik/semver#requirements.
176189
"req": "^0.6",
177190
// Array of features (as strings) enabled for this dependency.
178191
"features": ["i128_support"],
@@ -218,13 +231,6 @@ explaining the format of the entry.
218231
The JSON objects should not be modified after they are added except for the
219232
`yanked` field whose value may change at any time.
220233

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-
228234
### Web API
229235

230236
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:
286292
- 32-bit unsigned little-endian integer of the length of JSON data.
287293
- Metadata of the package as a JSON object.
288294
- 32-bit unsigned little-endian integer of the length of the `.crate` file.
289-
- The `.crate` fle.
295+
- The `.crate` file.
290296

291297
The following is a commented example of the JSON object. Some notes of some
292298
restrictions imposed by [crates.io] are included only to illustrate some
@@ -526,7 +532,7 @@ A successful response includes the JSON object:
526532

527533
#### Search
528534

529-
- Endpoint: `/api/v1/crates/crates`
535+
- Endpoint: `/api/v1/crates`
530536
- Method: GET
531537
- Query Parameters:
532538
- `q`: The search query string.

0 commit comments

Comments
 (0)