Skip to content

Commit ea9c1a5

Browse files
committed
Auto merge of #12313 - weihanglo:opaque-id, r=ehuss
doc: state `PackageId`/`SourceId` string is opaque
2 parents 45782b6 + f3fd9ef commit ea9c1a5

File tree

4 files changed

+158
-24
lines changed

4 files changed

+158
-24
lines changed

src/doc/man/cargo-metadata.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,34 @@ cargo-metadata --- Machine-readable metadata about the current package
1313
Output JSON to stdout containing information about the workspace members and
1414
resolved dependencies of the current package.
1515

16-
It is recommended to include the `--format-version` flag to future-proof
17-
your code to ensure the output is in the format you are expecting.
16+
The format of the output is subject to change in futures versions of Cargo. It
17+
is recommended to include the `--format-version` flag to future-proof your code
18+
to ensure the output is in the format you are expecting. For more on the
19+
expectations, see ["Compatibility"](#compatibility).
1820

1921
See the [cargo_metadata crate](https://crates.io/crates/cargo_metadata)
2022
for a Rust API for reading the metadata.
2123

2224
## OUTPUT FORMAT
2325

24-
The output has the following format:
26+
### Compatibility
27+
28+
Within the same output format version, the compatibility is maintained, except
29+
some scenarios. The following is a non-exhaustive list of changes that are not
30+
considersed as incompatibile:
31+
32+
* **Adding new fields** — New fields will be added when needed. Reserving this
33+
helps Cargo evolve without bumping the format version too often.
34+
* **Adding new values for enum-like fields** — Same as adding new fields. It
35+
keeps metadata evolving without stagnation.
36+
* **Changing opaque representations** — The inner representations of some
37+
fields are implementation details. For example, fields related to "Package ID"
38+
or "Source ID" are treated as opaque identifiers to differentiate packages or
39+
sources. Consumers shouldn't rely on those representations unless specified.
40+
41+
### JSON format
42+
43+
The JSON output has the following format:
2544

2645
```javascript
2746
{
@@ -34,22 +53,35 @@ The output has the following format:
3453
"name": "my-package",
3554
/* The version of the package. */
3655
"version": "0.1.0",
37-
/* The Package ID, a unique identifier for referring to the package. */
56+
/* The Package ID, an opaque and unique identifier for referring to the
57+
package. See "Compatibility" above for the stability guarantee.
58+
*/
3859
"id": "my-package 0.1.0 (path+file:///path/to/my-package)",
3960
/* The license value from the manifest, or null. */
4061
"license": "MIT/Apache-2.0",
4162
/* The license-file value from the manifest, or null. */
4263
"license_file": "LICENSE",
4364
/* The description value from the manifest, or null. */
4465
"description": "Package description.",
45-
/* The source ID of the package. This represents where
46-
a package is retrieved from.
66+
/* The source ID of the package, an "opaque" identifier representing
67+
where a package is retrieved from. See "Compatibility" above for
68+
the stability guarantee.
69+
4770
This is null for path dependencies and workspace members.
71+
4872
For other dependencies, it is a string with the format:
4973
- "registry+URL" for registry-based dependencies.
5074
Example: "registry+https://github.com/rust-lang/crates.io-index"
5175
- "git+URL" for git-based dependencies.
5276
Example: "git+https://github.com/rust-lang/cargo?rev=5e85ba14aaa20f8133863373404cb0af69eeef2c#5e85ba14aaa20f8133863373404cb0af69eeef2c"
77+
- "sparse+URL" for dependencies from a sparse registry
78+
Example: "sparse+https://my-sparse-registry.org"
79+
80+
The value after the `+` is not explicitly defined, and may change
81+
between versions of Cargo and may not directly correlate to other
82+
things, such as registry definitions in a config file. New source
83+
kinds may be added in the future which will have different `+`
84+
prefixed identifiers.
5385
*/
5486
"source": null,
5587
/* Array of dependencies declared in the package's manifest. */

src/doc/man/generated_txt/cargo-metadata.txt

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,34 @@ DESCRIPTION
1010
Output JSON to stdout containing information about the workspace members
1111
and resolved dependencies of the current package.
1212

13-
It is recommended to include the --format-version flag to future-proof
14-
your code to ensure the output is in the format you are expecting.
13+
The format of the output is subject to change in futures versions of
14+
Cargo. It is recommended to include the --format-version flag to
15+
future-proof your code to ensure the output is in the format you are
16+
expecting. For more on the expectations, see “Compatibility”.
1517

1618
See the cargo_metadata crate <https://crates.io/crates/cargo_metadata>
1719
for a Rust API for reading the metadata.
1820

1921
OUTPUT FORMAT
20-
The output has the following format:
22+
Compatibility
23+
Within the same output format version, the compatibility is maintained,
24+
except some scenarios. The following is a non-exhaustive list of changes
25+
that are not considersed as incompatibile:
26+
27+
o Adding new fields — New fields will be added when needed. Reserving
28+
this helps Cargo evolve without bumping the format version too often.
29+
30+
o Adding new values for enum-like fields — Same as adding new fields.
31+
It keeps metadata evolving without stagnation.
32+
33+
o Changing opaque representations — The inner representations of some
34+
fields are implementation details. For example, fields related to
35+
“Package ID” or “Source ID” are treated as opaque identifiers
36+
to differentiate packages or sources. Consumers shouldn’t rely on
37+
those representations unless specified.
38+
39+
JSON format
40+
The JSON output has the following format:
2141

2242
{
2343
/* Array of all packages in the workspace.
@@ -29,22 +49,35 @@ OUTPUT FORMAT
2949
"name": "my-package",
3050
/* The version of the package. */
3151
"version": "0.1.0",
32-
/* The Package ID, a unique identifier for referring to the package. */
52+
/* The Package ID, an opaque and unique identifier for referring to the
53+
package. See "Compatibility" above for the stability guarantee.
54+
*/
3355
"id": "my-package 0.1.0 (path+file:///path/to/my-package)",
3456
/* The license value from the manifest, or null. */
3557
"license": "MIT/Apache-2.0",
3658
/* The license-file value from the manifest, or null. */
3759
"license_file": "LICENSE",
3860
/* The description value from the manifest, or null. */
3961
"description": "Package description.",
40-
/* The source ID of the package. This represents where
41-
a package is retrieved from.
62+
/* The source ID of the package, an "opaque" identifier representing
63+
where a package is retrieved from. See "Compatibility" above for
64+
the stability guarantee.
65+
4266
This is null for path dependencies and workspace members.
67+
4368
For other dependencies, it is a string with the format:
4469
- "registry+URL" for registry-based dependencies.
4570
Example: "registry+https://github.com/rust-lang/crates.io-index"
4671
- "git+URL" for git-based dependencies.
4772
Example: "git+https://github.com/rust-lang/cargo?rev=5e85ba14aaa20f8133863373404cb0af69eeef2c#5e85ba14aaa20f8133863373404cb0af69eeef2c"
73+
- "sparse+URL" for dependencies from a sparse registry
74+
Example: "sparse+https://my-sparse-registry.org"
75+
76+
The value after the `+` is not explicitly defined, and may change
77+
between versions of Cargo and may not directly correlate to other
78+
things, such as registry definitions in a config file. New source
79+
kinds may be added in the future which will have different `+`
80+
prefixed identifiers.
4881
*/
4982
"source": null,
5083
/* Array of dependencies declared in the package's manifest. */

src/doc/src/commands/cargo-metadata.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,34 @@ cargo-metadata --- Machine-readable metadata about the current package
1313
Output JSON to stdout containing information about the workspace members and
1414
resolved dependencies of the current package.
1515

16-
It is recommended to include the `--format-version` flag to future-proof
17-
your code to ensure the output is in the format you are expecting.
16+
The format of the output is subject to change in futures versions of Cargo. It
17+
is recommended to include the `--format-version` flag to future-proof your code
18+
to ensure the output is in the format you are expecting. For more on the
19+
expectations, see ["Compatibility"](#compatibility).
1820

1921
See the [cargo_metadata crate](https://crates.io/crates/cargo_metadata)
2022
for a Rust API for reading the metadata.
2123

2224
## OUTPUT FORMAT
2325

24-
The output has the following format:
26+
### Compatibility
27+
28+
Within the same output format version, the compatibility is maintained, except
29+
some scenarios. The following is a non-exhaustive list of changes that are not
30+
considersed as incompatibile:
31+
32+
* **Adding new fields** — New fields will be added when needed. Reserving this
33+
helps Cargo evolve without bumping the format version too often.
34+
* **Adding new values for enum-like fields** — Same as adding new fields. It
35+
keeps metadata evolving without stagnation.
36+
* **Changing opaque representations** — The inner representations of some
37+
fields are implementation details. For example, fields related to "Package ID"
38+
or "Source ID" are treated as opaque identifiers to differentiate packages or
39+
sources. Consumers shouldn't rely on those representations unless specified.
40+
41+
### JSON format
42+
43+
The JSON output has the following format:
2544

2645
```javascript
2746
{
@@ -34,22 +53,35 @@ The output has the following format:
3453
"name": "my-package",
3554
/* The version of the package. */
3655
"version": "0.1.0",
37-
/* The Package ID, a unique identifier for referring to the package. */
56+
/* The Package ID, an opaque and unique identifier for referring to the
57+
package. See "Compatibility" above for the stability guarantee.
58+
*/
3859
"id": "my-package 0.1.0 (path+file:///path/to/my-package)",
3960
/* The license value from the manifest, or null. */
4061
"license": "MIT/Apache-2.0",
4162
/* The license-file value from the manifest, or null. */
4263
"license_file": "LICENSE",
4364
/* The description value from the manifest, or null. */
4465
"description": "Package description.",
45-
/* The source ID of the package. This represents where
46-
a package is retrieved from.
66+
/* The source ID of the package, an "opaque" identifier representing
67+
where a package is retrieved from. See "Compatibility" above for
68+
the stability guarantee.
69+
4770
This is null for path dependencies and workspace members.
71+
4872
For other dependencies, it is a string with the format:
4973
- "registry+URL" for registry-based dependencies.
5074
Example: "registry+https://github.com/rust-lang/crates.io-index"
5175
- "git+URL" for git-based dependencies.
5276
Example: "git+https://github.com/rust-lang/cargo?rev=5e85ba14aaa20f8133863373404cb0af69eeef2c#5e85ba14aaa20f8133863373404cb0af69eeef2c"
77+
- "sparse+URL" for dependencies from a sparse registry
78+
Example: "sparse+https://my-sparse-registry.org"
79+
80+
The value after the `+` is not explicitly defined, and may change
81+
between versions of Cargo and may not directly correlate to other
82+
things, such as registry definitions in a config file. New source
83+
kinds may be added in the future which will have different `+`
84+
prefixed identifiers.
5385
*/
5486
"source": null,
5587
/* Array of dependencies declared in the package's manifest. */

src/etc/man/cargo-metadata.1

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,37 @@ cargo\-metadata \[em] Machine\-readable metadata about the current package
1111
Output JSON to stdout containing information about the workspace members and
1212
resolved dependencies of the current package.
1313
.sp
14-
It is recommended to include the \fB\-\-format\-version\fR flag to future\-proof
15-
your code to ensure the output is in the format you are expecting.
14+
The format of the output is subject to change in futures versions of Cargo. It
15+
is recommended to include the \fB\-\-format\-version\fR flag to future\-proof your code
16+
to ensure the output is in the format you are expecting. For more on the
17+
expectations, see \[lq]Compatibility\[rq]\&.
1618
.sp
1719
See the \fIcargo_metadata crate\fR <https://crates.io/crates/cargo_metadata>
1820
for a Rust API for reading the metadata.
1921
.SH "OUTPUT FORMAT"
20-
The output has the following format:
22+
.SS "Compatibility"
23+
Within the same output format version, the compatibility is maintained, except
24+
some scenarios. The following is a non\-exhaustive list of changes that are not
25+
considersed as incompatibile:
26+
.sp
27+
.RS 4
28+
\h'-04'\(bu\h'+02'\fBAdding new fields\fR \[em] New fields will be added when needed. Reserving this
29+
helps Cargo evolve without bumping the format version too often.
30+
.RE
31+
.sp
32+
.RS 4
33+
\h'-04'\(bu\h'+02'\fBAdding new values for enum\-like fields\fR \[em] Same as adding new fields. It
34+
keeps metadata evolving without stagnation.
35+
.RE
36+
.sp
37+
.RS 4
38+
\h'-04'\(bu\h'+02'\fBChanging opaque representations\fR \[em] The inner representations of some
39+
fields are implementation details. For example, fields related to \[lq]Package ID\[rq]
40+
or \[lq]Source ID\[rq] are treated as opaque identifiers to differentiate packages or
41+
sources. Consumers shouldn\[cq]t rely on those representations unless specified.
42+
.RE
43+
.SS "JSON format"
44+
The JSON output has the following format:
2145
.sp
2246
.RS 4
2347
.nf
@@ -31,22 +55,35 @@ The output has the following format:
3155
"name": "my\-package",
3256
/* The version of the package. */
3357
"version": "0.1.0",
34-
/* The Package ID, a unique identifier for referring to the package. */
58+
/* The Package ID, an opaque and unique identifier for referring to the
59+
package. See "Compatibility" above for the stability guarantee.
60+
*/
3561
"id": "my\-package 0.1.0 (path+file:///path/to/my\-package)",
3662
/* The license value from the manifest, or null. */
3763
"license": "MIT/Apache\-2.0",
3864
/* The license\-file value from the manifest, or null. */
3965
"license_file": "LICENSE",
4066
/* The description value from the manifest, or null. */
4167
"description": "Package description.",
42-
/* The source ID of the package. This represents where
43-
a package is retrieved from.
68+
/* The source ID of the package, an "opaque" identifier representing
69+
where a package is retrieved from. See "Compatibility" above for
70+
the stability guarantee.
71+
4472
This is null for path dependencies and workspace members.
73+
4574
For other dependencies, it is a string with the format:
4675
\- "registry+URL" for registry\-based dependencies.
4776
Example: "registry+https://github.com/rust\-lang/crates.io\-index"
4877
\- "git+URL" for git\-based dependencies.
4978
Example: "git+https://github.com/rust\-lang/cargo?rev=5e85ba14aaa20f8133863373404cb0af69eeef2c#5e85ba14aaa20f8133863373404cb0af69eeef2c"
79+
\- "sparse+URL" for dependencies from a sparse registry
80+
Example: "sparse+https://my\-sparse\-registry.org"
81+
82+
The value after the `+` is not explicitly defined, and may change
83+
between versions of Cargo and may not directly correlate to other
84+
things, such as registry definitions in a config file. New source
85+
kinds may be added in the future which will have different `+`
86+
prefixed identifiers.
5087
*/
5188
"source": null,
5289
/* Array of dependencies declared in the package's manifest. */

0 commit comments

Comments
 (0)