3
3
//! These types are the public API exposed through the `--output-format json` flag. The [`Crate`]
4
4
//! struct is the root of the JSON blob and all other items are contained within.
5
5
6
+ use std:: collections:: { HashMap , HashSet } ;
6
7
use std:: path:: PathBuf ;
7
8
8
- use std:: collections:: HashMap ;
9
9
use serde:: { Deserialize , Serialize } ;
10
10
11
11
/// A `Crate` is the root of the emitted JSON blob. It contains all type/documentation information
@@ -64,7 +64,7 @@ pub struct Item {
64
64
pub name : Option < String > ,
65
65
/// The source location of this item (absent if it came from a macro expansion or inline
66
66
/// assembly).
67
- pub source : Option < Span > ,
67
+ pub span : Option < Span > ,
68
68
/// By default all documented items are public, but you can tell rustdoc to output private items
69
69
/// so this field is needed to differentiate.
70
70
pub visibility : Visibility ,
@@ -76,7 +76,7 @@ pub struct Item {
76
76
/// Stringified versions of the attributes on this item (e.g. `"#[inline]"`)
77
77
pub attrs : Vec < String > ,
78
78
pub deprecation : Option < Deprecation > ,
79
- pub kind : ItemKind ,
79
+ # [ serde ( flatten ) ]
80
80
pub inner : ItemEnum ,
81
81
}
82
82
@@ -96,8 +96,8 @@ pub struct Deprecation {
96
96
pub note : Option < String > ,
97
97
}
98
98
99
- #[ serde( rename_all = "snake_case" ) ]
100
99
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
100
+ #[ serde( rename_all = "snake_case" ) ]
101
101
pub enum Visibility {
102
102
Public ,
103
103
/// For the most part items are private by default. The exceptions are associated items of
@@ -112,17 +112,17 @@ pub enum Visibility {
112
112
} ,
113
113
}
114
114
115
- #[ serde( rename_all = "snake_case" ) ]
116
115
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
116
+ #[ serde( rename_all = "snake_case" ) ]
117
117
pub enum GenericArgs {
118
118
/// <'a, 32, B: Copy, C = u32>
119
119
AngleBracketed { args : Vec < GenericArg > , bindings : Vec < TypeBinding > } ,
120
120
/// Fn(A, B) -> C
121
121
Parenthesized { inputs : Vec < Type > , output : Option < Type > } ,
122
122
}
123
123
124
- #[ serde( rename_all = "snake_case" ) ]
125
124
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
125
+ #[ serde( rename_all = "snake_case" ) ]
126
126
pub enum GenericArg {
127
127
Lifetime ( String ) ,
128
128
Type ( Type ) ,
@@ -144,8 +144,8 @@ pub struct TypeBinding {
144
144
pub binding : TypeBindingKind ,
145
145
}
146
146
147
- #[ serde( rename_all = "snake_case" ) ]
148
147
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
148
+ #[ serde( rename_all = "snake_case" ) ]
149
149
pub enum TypeBindingKind {
150
150
Equality ( Type ) ,
151
151
Constraint ( Vec < GenericBound > ) ,
@@ -154,8 +154,8 @@ pub enum TypeBindingKind {
154
154
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Serialize , Deserialize ) ]
155
155
pub struct Id ( pub String ) ;
156
156
157
- #[ serde( rename_all = "snake_case" ) ]
158
157
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
158
+ #[ serde( rename_all = "snake_case" ) ]
159
159
pub enum ItemKind {
160
160
Module ,
161
161
ExternCrate ,
@@ -184,48 +184,49 @@ pub enum ItemKind {
184
184
Keyword ,
185
185
}
186
186
187
- #[ serde( untagged) ]
188
187
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
188
+ #[ serde( tag = "kind" , content = "inner" , rename_all = "snake_case" ) ]
189
189
pub enum ItemEnum {
190
- ModuleItem ( Module ) ,
191
- ExternCrateItem {
190
+ Module ( Module ) ,
191
+ ExternCrate {
192
192
name : String ,
193
193
rename : Option < String > ,
194
194
} ,
195
- ImportItem ( Import ) ,
195
+ Import ( Import ) ,
196
196
197
- StructItem ( Struct ) ,
198
- StructFieldItem ( Type ) ,
199
- EnumItem ( Enum ) ,
200
- VariantItem ( Variant ) ,
197
+ Union ( Union ) ,
198
+ Struct ( Struct ) ,
199
+ StructField ( Type ) ,
200
+ Enum ( Enum ) ,
201
+ Variant ( Variant ) ,
201
202
202
- FunctionItem ( Function ) ,
203
+ Function ( Function ) ,
203
204
204
- TraitItem ( Trait ) ,
205
- TraitAliasItem ( TraitAlias ) ,
206
- MethodItem ( Method ) ,
207
- ImplItem ( Impl ) ,
205
+ Trait ( Trait ) ,
206
+ TraitAlias ( TraitAlias ) ,
207
+ Method ( Method ) ,
208
+ Impl ( Impl ) ,
208
209
209
- TypedefItem ( Typedef ) ,
210
- OpaqueTyItem ( OpaqueTy ) ,
211
- ConstantItem ( Constant ) ,
210
+ Typedef ( Typedef ) ,
211
+ OpaqueTy ( OpaqueTy ) ,
212
+ Constant ( Constant ) ,
212
213
213
- StaticItem ( Static ) ,
214
+ Static ( Static ) ,
214
215
215
216
/// `type`s from an extern block
216
- ForeignTypeItem ,
217
+ ForeignType ,
217
218
218
219
/// Declarative macro_rules! macro
219
- MacroItem ( String ) ,
220
- ProcMacroItem ( ProcMacro ) ,
220
+ Macro ( String ) ,
221
+ ProcMacro ( ProcMacro ) ,
221
222
222
- AssocConstItem {
223
+ AssocConst {
223
224
#[ serde( rename = "type" ) ]
224
225
type_ : Type ,
225
226
/// e.g. `const X: usize = 5;`
226
227
default : Option < String > ,
227
228
} ,
228
- AssocTypeItem {
229
+ AssocType {
229
230
bounds : Vec < GenericBound > ,
230
231
/// e.g. `type X = usize;`
231
232
default : Option < Type > ,
@@ -238,6 +239,14 @@ pub struct Module {
238
239
pub items : Vec < Id > ,
239
240
}
240
241
242
+ #[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
243
+ pub struct Union {
244
+ pub generics : Generics ,
245
+ pub fields_stripped : bool ,
246
+ pub fields : Vec < Id > ,
247
+ pub impls : Vec < Id > ,
248
+ }
249
+
241
250
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
242
251
pub struct Struct {
243
252
pub struct_type : StructType ,
@@ -255,37 +264,46 @@ pub struct Enum {
255
264
pub impls : Vec < Id > ,
256
265
}
257
266
267
+ #[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
258
268
#[ serde( rename_all = "snake_case" ) ]
259
269
#[ serde( tag = "variant_kind" , content = "variant_inner" ) ]
260
- #[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
261
270
pub enum Variant {
262
271
Plain ,
263
272
Tuple ( Vec < Type > ) ,
264
273
Struct ( Vec < Id > ) ,
265
274
}
266
275
267
- #[ serde( rename_all = "snake_case" ) ]
268
276
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
277
+ #[ serde( rename_all = "snake_case" ) ]
269
278
pub enum StructType {
270
279
Plain ,
271
280
Tuple ,
272
281
Unit ,
273
- Union ,
282
+ }
283
+
284
+ #[ non_exhaustive]
285
+ #[ derive( Clone , Debug , Serialize , Deserialize , PartialEq , Eq , Hash ) ]
286
+ #[ serde( rename_all = "snake_case" ) ]
287
+ pub enum Qualifiers {
288
+ Const ,
289
+ Unsafe ,
290
+ Async ,
274
291
}
275
292
276
293
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
277
294
pub struct Function {
278
295
pub decl : FnDecl ,
279
296
pub generics : Generics ,
280
- pub header : String ,
297
+ pub header : HashSet < Qualifiers > ,
281
298
pub abi : String ,
282
299
}
283
300
284
301
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
285
302
pub struct Method {
286
303
pub decl : FnDecl ,
287
304
pub generics : Generics ,
288
- pub header : String ,
305
+ pub header : HashSet < Qualifiers > ,
306
+ pub abi : String ,
289
307
pub has_body : bool ,
290
308
}
291
309
@@ -301,24 +319,24 @@ pub struct GenericParamDef {
301
319
pub kind : GenericParamDefKind ,
302
320
}
303
321
304
- #[ serde( rename_all = "snake_case" ) ]
305
322
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
323
+ #[ serde( rename_all = "snake_case" ) ]
306
324
pub enum GenericParamDefKind {
307
325
Lifetime ,
308
326
Type { bounds : Vec < GenericBound > , default : Option < Type > } ,
309
327
Const ( Type ) ,
310
328
}
311
329
312
- #[ serde( rename_all = "snake_case" ) ]
313
330
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
331
+ #[ serde( rename_all = "snake_case" ) ]
314
332
pub enum WherePredicate {
315
333
BoundPredicate { ty : Type , bounds : Vec < GenericBound > } ,
316
334
RegionPredicate { lifetime : String , bounds : Vec < GenericBound > } ,
317
335
EqPredicate { lhs : Type , rhs : Type } ,
318
336
}
319
337
320
- #[ serde( rename_all = "snake_case" ) ]
321
338
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
339
+ #[ serde( rename_all = "snake_case" ) ]
322
340
pub enum GenericBound {
323
341
TraitBound {
324
342
#[ serde( rename = "trait" ) ]
@@ -330,17 +348,17 @@ pub enum GenericBound {
330
348
Outlives ( String ) ,
331
349
}
332
350
333
- #[ serde( rename_all = "snake_case" ) ]
334
351
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
352
+ #[ serde( rename_all = "snake_case" ) ]
335
353
pub enum TraitBoundModifier {
336
354
None ,
337
355
Maybe ,
338
356
MaybeConst ,
339
357
}
340
358
359
+ #[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
341
360
#[ serde( rename_all = "snake_case" ) ]
342
361
#[ serde( tag = "kind" , content = "inner" ) ]
343
- #[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
344
362
pub enum Type {
345
363
/// Structs, enums, and traits
346
364
ResolvedPath {
@@ -395,9 +413,9 @@ pub enum Type {
395
413
396
414
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
397
415
pub struct FunctionPointer {
398
- pub is_unsafe : bool ,
399
- pub generic_params : Vec < GenericParamDef > ,
400
416
pub decl : FnDecl ,
417
+ pub generic_params : Vec < GenericParamDef > ,
418
+ pub header : HashSet < Qualifiers > ,
401
419
pub abi : String ,
402
420
}
403
421
@@ -439,11 +457,11 @@ pub struct Impl {
439
457
pub blanket_impl : Option < Type > ,
440
458
}
441
459
442
- #[ serde( rename_all = "snake_case" ) ]
443
460
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
461
+ #[ serde( rename_all = "snake_case" ) ]
444
462
pub struct Import {
445
463
/// The full path being imported.
446
- pub span : String ,
464
+ pub source : String ,
447
465
/// May be different from the last segment of `source` when renaming imports:
448
466
/// `use source as name;`
449
467
pub name : String ,
@@ -459,8 +477,8 @@ pub struct ProcMacro {
459
477
pub helpers : Vec < String > ,
460
478
}
461
479
462
- #[ serde( rename_all = "snake_case" ) ]
463
480
#[ derive( Clone , Debug , Serialize , Deserialize , PartialEq ) ]
481
+ #[ serde( rename_all = "snake_case" ) ]
464
482
pub enum MacroKind {
465
483
/// A bang macro `foo!()`.
466
484
Bang ,
@@ -490,3 +508,6 @@ pub struct Static {
490
508
pub mutable : bool ,
491
509
pub expr : String ,
492
510
}
511
+
512
+ #[ cfg( test) ]
513
+ mod tests;
0 commit comments