@@ -61,6 +61,8 @@ use rustc_middle::ty::print::PrintTraitRefExt;
61
61
use rustc_middle:: ty:: { self , TyCtxt } ;
62
62
use rustc_span:: symbol:: { Symbol , sym} ;
63
63
use rustc_span:: { BytePos , DUMMY_SP , FileName , RealFileName } ;
64
+ use serde:: ser:: SerializeSeq as _;
65
+ use serde:: { Deserialize , Serialize } ;
64
66
use tracing:: { debug, info} ;
65
67
66
68
pub ( crate ) use self :: context:: * ;
@@ -144,7 +146,7 @@ pub(crate) struct IndexItem {
144
146
}
145
147
146
148
/// A type used for the search index.
147
- #[ derive( Debug , Eq , PartialEq ) ]
149
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
148
150
struct RenderType {
149
151
id : Option < RenderTypeId > ,
150
152
generics : Option < Vec < RenderType > > ,
@@ -311,7 +313,7 @@ impl RenderTypeId {
311
313
}
312
314
313
315
/// Full type of functions/methods in the search index.
314
- #[ derive( Debug , Eq , PartialEq ) ]
316
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
315
317
pub ( crate ) struct IndexItemFunctionType {
316
318
inputs : Vec < RenderType > ,
317
319
output : Vec < RenderType > ,
@@ -410,6 +412,73 @@ impl IndexItemFunctionType {
410
412
}
411
413
}
412
414
415
+ impl Serialize for IndexItemFunctionType {
416
+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
417
+ where
418
+ S : serde:: Serializer ,
419
+ {
420
+ let mut seq = serializer. serialize_seq ( Some ( 2 ) ) ?;
421
+ seq. serialize_element ( & self . write_to_string_without_param_names ( ) . to_string ( ) ) ?;
422
+
423
+ struct ParamNames < ' a > ( & ' a [ Option < Symbol > ] ) ;
424
+
425
+ impl < ' a > Serialize for ParamNames < ' a > {
426
+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
427
+ where
428
+ S : serde:: Serializer ,
429
+ {
430
+ serializer. collect_seq (
431
+ self . 0
432
+ . iter ( )
433
+ . map ( |symbol| symbol. as_ref ( ) . map ( ToString :: to_string) . unwrap_or_default ( ) ) ,
434
+ )
435
+ }
436
+ }
437
+
438
+ seq. serialize_element ( & ParamNames ( & self . param_names ) ) ?;
439
+ seq. end ( )
440
+ }
441
+ }
442
+
443
+ impl < ' de > Deserialize < ' de > for IndexItemFunctionType {
444
+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
445
+ where
446
+ D : serde:: Deserializer < ' de > ,
447
+ {
448
+ use serde:: de:: { self , Error as _} ;
449
+
450
+ struct FunctionDataVisitor ;
451
+ impl < ' de > de:: Visitor < ' de > for FunctionDataVisitor {
452
+ type Value = IndexItemFunctionType ;
453
+ fn expecting ( & self , formatter : & mut std:: fmt:: Formatter < ' _ > ) -> fmt:: Result {
454
+ write ! ( formatter, "fn data" )
455
+ }
456
+ fn visit_seq < A : de:: SeqAccess < ' de > > ( self , mut v : A ) -> Result < Self :: Value , A :: Error > {
457
+ let ( mut function_signature, _) = v
458
+ . next_element ( ) ?
459
+ . map ( |fn_ : String | {
460
+ IndexItemFunctionType :: read_from_string_without_param_names ( fn_. as_bytes ( ) )
461
+ } )
462
+ . ok_or_else ( || A :: Error :: missing_field ( "function_signature" ) ) ?;
463
+ let param_names: Vec < Option < Symbol > > = v
464
+ . next_element ( ) ?
465
+ . map ( |param_names : Vec < String > | {
466
+ param_names
467
+ . into_iter ( )
468
+ . map ( |symbol| {
469
+ if symbol. is_empty ( ) { None } else { Some ( Symbol :: intern ( & symbol) ) }
470
+ } )
471
+ . collect ( )
472
+ } )
473
+ . ok_or_else ( || A :: Error :: missing_field ( "param_names" ) ) ?;
474
+ function_signature. param_names = param_names;
475
+ Ok ( function_signature)
476
+ }
477
+ }
478
+ deserializer. deserialize_any ( FunctionDataVisitor )
479
+ }
480
+ }
481
+
413
482
#[ derive( Debug , Clone ) ]
414
483
pub ( crate ) struct StylePath {
415
484
/// The path to the theme
0 commit comments