Skip to content

Commit 8f2da4a

Browse files
committed
Call out the differences between the index JSON and the API or metadata.
1 parent 0e474cf commit 8f2da4a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/doc/src/reference/registry-index.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,40 @@ explaining the format of the entry.
205205
The JSON objects should not be modified after they are added except for the
206206
`yanked` field whose value may change at any time.
207207

208+
> **Note**: The index JSON format has subtle differences from the JSON format of the [Publish API] and [`cargo metadata`].
209+
> If you are using one of those as a source to generate index entries, you are encouraged to carefully inspect the documentation differences between them.
210+
>
211+
> For the [Publish API], the differences are:
212+
>
213+
> * `deps`
214+
> * `name` --- When the dependency is [renamed] in `Cargo.toml`, the publish API puts the original package name in the `name` field and the aliased name in the `explicit_name_in_toml` field.
215+
> The index places the aliased name in the `name` field, and the original package name in the `package` field.
216+
> * `req` --- The Publish API field is called `version_req`.
217+
> * `cksum` --- The publish API does not specify the checksum, it must be computed by the registry before adding to the index.
218+
> * `features` --- Some features may be placed in the `features2` field.
219+
> Note: This is only a legacy requirement for [crates.io]; other registries should not need to bother with modifying the features map.
220+
> The `v` field indicates the presence of the `features2` field.
221+
> * The publish API includes several other fields, such as `description` and `readme`, which don't appear in the index.
222+
> These are intended to make it easier for a registry to obtain the metadata about the crate to display on a website without needing to extract and parse the `.crate` file.
223+
> This additional information is typically added to a database on the registry server.
224+
>
225+
> For [`cargo metadata`], the differences are:
226+
>
227+
> * `vers` --- The `cargo metadata` field is called `version`.
228+
> * `deps`
229+
> * `name` --- When the dependency is [renamed] in `Cargo.toml`, `cargo metadata` puts the original package name in the `name` field and the aliased name in the `rename` field.
230+
> The index places the aliased name in the `name` field, and the original package name in the `package` field.
231+
> * `default_features` --- The `cargo metadata` field is called `uses_default_features`.
232+
> * `registry` --- `cargo metadata` uses a value of `null` to indicate that the dependency comes from [crates.io].
233+
> The index uses a value of `null` to indicate that the dependency comes from the same registry as the index.
234+
> When creating an index entry, a registry other than [crates.io] should translate a value of `null` to be `https://github.com/rust-lang/crates.io-index` and translate a URL that matches the current index to be `null`.
235+
> * `cargo metadata` includes some extra fields, such as `source` and `path`.
236+
> * The index includes additional fields such as `yanked`, `cksum`, and `v`.
237+
238+
[renamed]: specifying-dependencies.md#renaming-dependencies-in-cargotoml
239+
[Publish API]: registry-web-api.md#publish
240+
[`cargo metadata`]: ../commands/cargo-metadata.md
241+
208242
### Index Protocols
209243
Cargo supports two remote registry protocols: `git` and `sparse`. The `git` protocol
210244
stores index files in a git repository and the `sparse` protocol fetches individual

0 commit comments

Comments
 (0)