@@ -110,63 +110,72 @@ pub(crate) struct IndexItem {
110
110
/// A type used for the search index.
111
111
#[ derive( Debug ) ]
112
112
pub ( crate ) struct RenderType {
113
- name : Option < String > ,
114
- generics : Option < Vec < TypeWithKind > > ,
113
+ id : Option < RenderTypeId > ,
114
+ generics : Option < Vec < RenderType > > ,
115
115
}
116
116
117
- /// Full type of functions/methods in the search index.
118
- #[ derive( Debug ) ]
119
- pub ( crate ) struct IndexItemFunctionType {
120
- inputs : Vec < TypeWithKind > ,
121
- output : Vec < TypeWithKind > ,
122
- }
123
-
124
- impl Serialize for IndexItemFunctionType {
117
+ impl Serialize for RenderType {
125
118
fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
126
119
where
127
120
S : Serializer ,
128
121
{
129
- // If we couldn't figure out a type, just write `null`.
130
- let has_missing = self . inputs . iter ( ) . chain ( self . output . iter ( ) ) . any ( |i| i. ty . name . is_none ( ) ) ;
131
- if has_missing {
132
- serializer. serialize_none ( )
133
- } else {
122
+ let id = match & self . id {
123
+ // 0 is a sentinel, everything else is one-indexed
124
+ None => 0 ,
125
+ Some ( RenderTypeId :: Index ( idx) ) => idx + 1 ,
126
+ _ => panic ! ( "must convert render types to indexes before serializing" ) ,
127
+ } ;
128
+ if let Some ( generics) = & self . generics {
134
129
let mut seq = serializer. serialize_seq ( None ) ?;
135
- seq. serialize_element ( & self . inputs ) ?;
136
- match self . output . as_slice ( ) {
137
- [ ] => { }
138
- [ one] => seq. serialize_element ( one) ?,
139
- all => seq. serialize_element ( all) ?,
140
- }
130
+ seq. serialize_element ( & id) ?;
131
+ seq. serialize_element ( generics) ?;
141
132
seq. end ( )
133
+ } else {
134
+ id. serialize ( serializer)
142
135
}
143
136
}
144
137
}
145
138
146
- #[ derive( Debug ) ]
147
- pub ( crate ) struct TypeWithKind {
148
- ty : RenderType ,
149
- kind : ItemType ,
139
+ #[ derive( Clone , Debug ) ]
140
+ pub ( crate ) enum RenderTypeId {
141
+ DefId ( DefId ) ,
142
+ Primitive ( clean:: PrimitiveType ) ,
143
+ Index ( usize ) ,
150
144
}
151
145
152
- impl From < ( RenderType , ItemType ) > for TypeWithKind {
153
- fn from ( x : ( RenderType , ItemType ) ) -> TypeWithKind {
154
- TypeWithKind { ty : x. 0 , kind : x. 1 }
155
- }
146
+ /// Full type of functions/methods in the search index.
147
+ #[ derive( Debug ) ]
148
+ pub ( crate ) struct IndexItemFunctionType {
149
+ inputs : Vec < RenderType > ,
150
+ output : Vec < RenderType > ,
156
151
}
157
152
158
- impl Serialize for TypeWithKind {
153
+ impl Serialize for IndexItemFunctionType {
159
154
fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
160
155
where
161
156
S : Serializer ,
162
157
{
163
- let mut seq = serializer. serialize_seq ( None ) ?;
164
- seq. serialize_element ( & self . ty . name ) ?;
165
- seq. serialize_element ( & self . kind ) ?;
166
- if let Some ( generics) = & self . ty . generics {
167
- seq. serialize_element ( generics) ?;
158
+ // If we couldn't figure out a type, just write `0`.
159
+ let has_missing = self
160
+ . inputs
161
+ . iter ( )
162
+ . chain ( self . output . iter ( ) )
163
+ . any ( |i| i. id . is_none ( ) && i. generics . is_none ( ) ) ;
164
+ if has_missing {
165
+ 0 . serialize ( serializer)
166
+ } else {
167
+ let mut seq = serializer. serialize_seq ( None ) ?;
168
+ match & self . inputs [ ..] {
169
+ [ one] if one. generics . is_none ( ) => seq. serialize_element ( one) ?,
170
+ _ => seq. serialize_element ( & self . inputs ) ?,
171
+ }
172
+ match & self . output [ ..] {
173
+ [ ] => { }
174
+ [ one] if one. generics . is_none ( ) => seq. serialize_element ( one) ?,
175
+ _ => seq. serialize_element ( & self . output ) ?,
176
+ }
177
+ seq. end ( )
168
178
}
169
- seq. end ( )
170
179
}
171
180
}
172
181
@@ -2517,7 +2526,6 @@ fn item_ty_to_section(ty: ItemType) -> ItemSection {
2517
2526
ItemType :: ProcAttribute => ItemSection :: AttributeMacros ,
2518
2527
ItemType :: ProcDerive => ItemSection :: DeriveMacros ,
2519
2528
ItemType :: TraitAlias => ItemSection :: TraitAliases ,
2520
- ItemType :: Generic => unreachable ! ( ) ,
2521
2529
}
2522
2530
}
2523
2531
0 commit comments