1
1
- Feature Name: ` rustdoc_json `
2
2
- Start Date: 2020-06-26
3
- - RFC PR: (leave this empty )
4
- - Rust Issue: (leave this empty )
3
+ - RFC PR: [ rust-lang/rfcs # 2963 ] ( https://github.com/rust-lang/rfcs/pull/2963 )
4
+ - Rust Issue: [ rust-lang/rust # 0000 ] ( https://github.com/rust-lang/rust/issues/0000 )
5
5
6
6
# Summary
7
7
[ summary ] : #summary
@@ -96,16 +96,14 @@ After running the above command, you should get a `lib.json` file like the follo
96
96
"attrs" : [],
97
97
"kind" : " function" ,
98
98
"inner" : {
99
- "function_item" : {
100
- "decl" : {
101
- "inputs" : [],
102
- "output" : null ,
103
- "c_variadic" : false
104
- },
105
- "generics" : {... },
106
- "header" : " " ,
107
- "abi" : " \" Rust\" "
108
- }
99
+ "decl" : {
100
+ "inputs" : [],
101
+ "output" : null ,
102
+ "c_variadic" : false
103
+ },
104
+ "generics" : {... },
105
+ "header" : " " ,
106
+ "abi" : " \" Rust\" "
109
107
}
110
108
},
111
109
"0:4" : {
@@ -121,13 +119,11 @@ After running the above command, you should get a `lib.json` file like the follo
121
119
"attrs" : [],
122
120
"kind" : " struct" ,
123
121
"inner" : {
124
- "struct_item" : {
125
- "struct_type" : " unit" ,
126
- "generics" : {... },
127
- "fields_stripped" : false ,
128
- "fields" : [],
129
- "impls" : [... ]
130
- }
122
+ "struct_type" : " unit" ,
123
+ "generics" : {... },
124
+ "fields_stripped" : false ,
125
+ "fields" : [],
126
+ "impls" : [... ]
131
127
}
132
128
},
133
129
"0:0" : {
@@ -143,13 +139,11 @@ After running the above command, you should get a `lib.json` file like the follo
143
139
"attrs" : [],
144
140
"kind" : " module" ,
145
141
"inner" : {
146
- "module_item" : {
147
- "is_crate" : true ,
148
- "items" : [
149
- " 0:4" ,
150
- " 0:3"
151
- ]
152
- }
142
+ "is_crate" : true ,
143
+ "items" : [
144
+ " 0:4" ,
145
+ " 0:3"
146
+ ]
153
147
}
154
148
}
155
149
},
@@ -165,7 +159,7 @@ After running the above command, you should get a `lib.json` file like the follo
165
159
"kind" : " struct"
166
160
},
167
161
...
168
- }
162
+ },
169
163
"extern_crates" : {
170
164
"9" : {
171
165
"name" : " backtrace" ,
@@ -261,7 +255,8 @@ Name | Type | Description
261
255
` span ` | [ Span] ( #Span ) | The source location of this Item.
262
256
` visibility ` | String | ` "default" ` , ` "public" ` , ` "crate" ` , or ` "restricted" ` (` pub(path) ` ). TODO: show how the restricted path info is represented.
263
257
` docs ` | String | The extracted documentation text from the Item.
264
- ` attrs ` | [ String] | The attributes (other than doc comments) on the Item, rendered as strings.
258
+ ` attrs ` | [ String] | The attributes (other than doc comments) on the Item, rendered as strings.
259
+ ` deprecation ` | [ Deprecation] ( #Deprecation ) | (* Optional* ) Information about the Item's deprecation, if present.
265
260
` kind ` | String | The kind of Item this is. Determines what fields are in ` inner ` .
266
261
` inner ` | Object | The type-specific fields describing this Item. Check the ` kind ` field to determine what's available.
267
262
@@ -271,16 +266,13 @@ Name | Type | Description
271
266
---------|--------|--------------------------------------------------------------------------------
272
267
` items ` | [[ ID] ( #ID )] | The list of Items contained within this module. The order of definitions is preserved.
273
268
274
- ### ` kind == "function" || "foreign_function" `
275
-
276
- Foreign functions are ` fn ` s from an ` extern ` block
269
+ ### ` kind == "function" `
277
270
278
271
Name | Type | Description
279
272
-----------|----------|----------------------------------------------------------------------------
280
273
` decl ` | [ FnDecl] ( #FnDecl ) | Information about the function signature, or declaration.
281
274
` generics ` | [ Generics] ( #Generics ) | Information about the function's type parameters and ` where ` clauses.
282
- ` header ` | String | ` "const" ` , ` "async" ` , ` "unsafe" ` , or a space separated combination of those
283
- modifiers.
275
+ ` header ` | String | ` "const" ` , ` "async" ` , ` "unsafe" ` , or a space separated combination of those modifiers.
284
276
` abi ` | String | The ABI string on the function. Non-` extern ` functions have a ` "Rust" ` ABI, whereas ` extern ` functions without an explicit ABI are ` "C" ` . See [ the reference] ( https://doc.rust-lang.org/reference/items/external-blocks.html#abi ) for more details.
285
277
286
278
### ` kind == "struct" || "union" `
@@ -346,6 +338,24 @@ Name | Type | Description
346
338
modifiers.
347
339
` has_body ` | bool | Whether this is just a method signature (in a trait definition) or a method with an actual body.
348
340
341
+ ### ` kind == "assoc_const" `
342
+
343
+ These items only show up in trait _ definitions_ . When looking at a trait impl item, the item where the associated constant is defined is a ` "constant" ` item.
344
+
345
+ Name | Type | Description
346
+ --------------|----------|-------------------------------------------------------------------------
347
+ ` type ` | [ Type] ( #Type ) | The type of this associated const.
348
+ ` default ` | String | (* Optional* ) The stringified expression for the default value, if provided.
349
+
350
+ ### ` kind == "assoc_type" `
351
+
352
+ These items only show up in trait _ definitions_ . When looking at a trait impl item, the item where the associated type is defined is a ` "typedef" ` item.
353
+
354
+ Name | Type | Description
355
+ --------------|----------|-------------------------------------------------------------------------
356
+ ` bounds ` | [[ GenericBound] ( #GenericBound )] | The bounds for this associated type.
357
+ ` default ` | [ Type] ( #Type ) | (* Optional* ) The default for this type, if provided.
358
+
349
359
### ` kind == "impl" `
350
360
351
361
Name | Type | Description
@@ -384,42 +394,61 @@ Name | Type | Description
384
394
` type ` | [ Type] ( #Type ) | The type on the right hand side of this definition.
385
395
` generics ` | [ Generics] ( #Generics ) | Any generic parameters on the left hand side of this definition.
386
396
387
- ### ` kind == "assoc_const" `
388
-
389
- These items only show up in trait _ definitions_ . When looking at a trait impl item, the item where the associated constant is defined is a ` "constant" ` item.
390
-
391
- Name | Type | Description
392
- --------------|----------|-------------------------------------------------------------------------
393
- ` type ` | [ Type] ( #Type ) | The type of this associated const.
394
- ` default ` | String | (* Optional* ) The stringified expression for the default value, if provided.
397
+ ### ` kind == "opaque_ty" `
395
398
396
- ### ` kind == "assoc_type" `
399
+ Represents [ trait aliases] ( https://doc.rust-lang.org/beta/unstable-book/language-features/trait-alias.html )
400
+ of the form:
397
401
398
- These items only show up in trait _ definitions_ . When looking at a trait impl item, the item where the associated type is defined is a ` "typedef" ` item.
402
+ ``` rust
403
+ type Foo <T > = Clone + std :: fmt :: Debug + Into <T >;
404
+ ```
399
405
400
406
Name | Type | Description
401
407
--------------|----------|-------------------------------------------------------------------------
402
- ` bounds ` | [[ GenericBound] ( #GenericBound )] | The bounds for this associated type .
403
- ` default ` | [ Type ] ( #Type ) | ( * Optional * ) The default for this type, if provided .
408
+ ` bounds ` | [[ GenericBound] ( #GenericBound )] | The trait bounds on the right hand side .
409
+ ` generics ` | [ Generics ] ( #Generics ) | Any generic parameters on the type itself .
404
410
405
411
### ` kind == "foreign_type" `
406
412
407
- Name | Type | Description
408
- --------------|----------|-------------------------------------------------------------------------
409
- ` bounds ` | [[ GenericBound] ( #GenericBound )] | The bounds for this associated type.
410
- ` default ` | [ Type] ( #Type ) | (* Optional* ) The default for this type, if provided.
413
+ ` inner ` contains no fields. This item represents a type declaration in an extern block (see [ here] ( https://github.com/rust-lang/rfcs/blob/master/text/1861-extern-types.md )
414
+ for more details):
415
+
416
+ ``` rust
417
+ extern {
418
+ type Foo ;
419
+ }
420
+ ```
411
421
412
422
### ` kind == "extern_crate" `
413
- TODO
423
+
424
+ Name | Type | Description
425
+ ---------|----------|-------------------------------------------------------------------------
426
+ ` name ` | String | The name of the extern crate.
427
+ ` rename ` | String | (* Optional* ) The renaming of this crate with ` extern crate foo as bar ` .
428
+
414
429
### ` kind == "import" `
415
- TODO
416
- ### ` kind == "opaque_ty" `
417
- TODO
430
+
431
+ Name | Type | Description
432
+ ---------|----------|-------------------------------------------------------------------------
433
+ ` source ` | String | The full path being imported (e.g. ` "super::some_mod::other_mod::Struct" ` ).
434
+ ` name ` | String | The name of the imported item (may be different from the last segment of ` source ` due to import renaming: ` use source as name ` ).
435
+ ` id ` | [ ID] ( #ID ) | (* Optional* ) The ID of the item being imported.
436
+ ` glob ` | bool | Whether this import ends in a glob: ` use source::* ` .
437
+
418
438
### ` kind == "macro" `
419
- TODO
420
- ### ` kind == "proc_attribute" `
421
- TODO
422
- ### ` kind == "proc_derive" `
439
+
440
+ A ` macro_rules! ` declarative macro. Contains a single string with the source representation of
441
+ the macro with the patterns stripped, for example:
442
+
443
+ ``` rust
444
+ macro_rules! vec {
445
+ () => { ... };
446
+ ($ elem : expr ; $ n : expr ) => { ... };
447
+ ($ ($ x : expr ),+ $ (,)? ) => { ... };
448
+ }
449
+ ```
450
+
451
+ TODO: proc macros
423
452
424
453
## Span
425
454
@@ -429,6 +458,13 @@ Name | Type | Description
429
458
` begin ` | (int, int) | The zero indexed line and column of the first character in this span.
430
459
` begin ` | (int, int) | The zero indexed line and column of the last character in this span.
431
460
461
+ ## Deprecation
462
+
463
+ Name | Type | Description
464
+ -----------|----------|----------------------------------------------------------------------------
465
+ ` since ` | String | Usually a version number when this Item first became deprecated.
466
+ ` note ` | String | The reason for deprecation and/or what alternatives to use.
467
+
432
468
## FnDecl
433
469
434
470
Name | Type | Description
@@ -589,7 +625,7 @@ Name | Type | Description
589
625
590
626
Name | Type | Description
591
627
-----------|----------|----------------------------------------------------------------------------
592
- ` bounds ` | [ GenericBound] ( #GenericBound ) | The bounds on this parameter.
628
+ ` bounds ` | [[ GenericBound] ( #GenericBound )] | The bounds on this parameter.
593
629
` default ` | [ Type] ( #Type ) | (* Optional* ) The default type for this parameter (e.g ` PartialEq<Rhs = Self> ` ).
594
630
595
631
### WherePredicate
@@ -996,7 +1032,7 @@ pub fn generic_args<'a>(x: impl MyTrait<'a, i32, Item = u8, Other = f32>) {
996
1032
available parsers, but selecting a different data format may provide benefits for file size,
997
1033
compressibility, speed of conversion, etc. Since the implementation will lean on serde then this
998
1034
may be a non-issue as it would be trivial to switch serialization formats.
999
- - ** Alternate data structure.** The proposed output very closely mirrors the internal ` Clean ` AST
1035
+ - ** Alternate data structure.** The proposed output very closely mirrors the internal ` clean ` AST
1000
1036
types in rustdoc. This simplifies the implementation but may not be the optimal structure for
1001
1037
users. If there are significant improvements then a future RFC could provide the necessary
1002
1038
refinements, potentially as another alternative output format if necessary.
@@ -1068,9 +1104,9 @@ include spans, but doesn't do any of the other things mentioned here.
1068
1104
path in the spans, but it's probably preferable to have it just list the filename for single
1069
1105
files or the path from the crate root for cargo projects.
1070
1106
- The proposed implementation exposes a strict subset of the information available to the HTML,
1071
- backend: the ` Clean ` types for Items and some mappings from the ` Cache ` . Are there other
1107
+ backend: the ` clean ` types for Items and some mappings from the ` Cache ` . Are there other
1072
1108
mappings/info from elsewhere that would be helpful to expose to users?
1073
- - There are some items such as attributes that defer to compiler internal symbols in their ` Clean `
1109
+ - There are some items such as attributes that defer to compiler internal symbols in their ` clean `
1074
1110
representations which would make them problematic to represent faithfully. Is it OK to simply
1075
1111
stringify these and leave their handling up to the user?
1076
1112
- Should we specially handle ` Deref ` trait impls to make it easier for a struct to find the methods
0 commit comments