You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Json ID's are opaque, and may be changed at any point (In fact, I;m: To quote the [rfc](https://rust-lang.github.io/rfcs/2963-rustdoc-json.html#id):
> They happen to be the compiler internal DefId for that item, but in the JSON blob they should be treated as opaque as they aren't guaranteed to be stable across compiler invocations.
In fact, Its possible rustdoc should mangle `Id`s, so they dont look human readable, because they arn't indended to convey any information themself.
Also: Thanks for writing this post, and I'm super glad to see people finding uses for rustdoc-json. Please file issues if you run into anything or can think of improvements to the json format.
Copy file name to clipboardExpand all lines: content/abcr-issue-0.md
+11-9Lines changed: 11 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
+++
2
2
title = "A better cargo-readme - Issue 0: Humble Beginning"
3
3
date = 2021-12-06
4
+
updated = 2021-12-08
4
5
+++
5
6
6
7
# Introduction
@@ -205,19 +206,16 @@ The JSON document follows a specific structure defined in the `rustdoc_json_type
205
206
206
207
## Extracting the crate-level documentation
207
208
208
-
After a few minutes of diving in the data structures, we can see that all the items that are reachable from the crate are located in the [`index`] field. This field is a JSON dictionary whose keys are the compiler-generated [`DefId`] and values are metadata of the reachable items. Looking at the documentation of the [`def_id`] module tells us that we should look at the crate id 0. After some researches, it turns out that the crate-level documentation are available at for the [`DefId`] "0:0".
209
-
210
-
I think that the second 0 comes from the order in which the different items of a crate are lowered by Rustc, but that's another story.
209
+
After a few minutes of diving in the data structures, we can see that all the items that are reachable from the crate are located in the [`index`] field. This field is a JSON dictionary whose keys are compiler-generated [`Id`]s and values are metadata of the reachable items. Additionally, there is a [`root`] field, which tells us which key in the index map will give us the documentation for the crate's root module.
211
210
212
211
Let's try to write a command which extracts the crate-level documentation using `jq`:
@@ -271,4 +269,8 @@ This issue was reviewed by volunteers who gave me a lot of feedback. They are, i
271
269
-[Natsukoh](https://twitter.com/natsukoow),
272
270
-[Yozhgoor 🦀](https://twitter.com/yozhgoor).
273
271
272
+
Initial release of the blogpost used a hardcoded `id` to retrieve the crate-level documentation. [@aDotInTheVoid] suggested to use the `root` field instead. Thanks!
If you're interested in reviewing the next articles or implementation, don't hesitate to message me on Twitter. I gladly welcome any kind of constructive feedback.
0 commit comments