@@ -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 > > ,
@@ -301,7 +303,7 @@ impl RenderTypeId {
301
303
}
302
304
303
305
/// Full type of functions/methods in the search index.
304
- #[ derive( Debug , Eq , PartialEq ) ]
306
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
305
307
pub ( crate ) struct IndexItemFunctionType {
306
308
inputs : Vec < RenderType > ,
307
309
output : Vec < RenderType > ,
@@ -423,6 +425,75 @@ impl IndexItemFunctionType {
423
425
}
424
426
}
425
427
428
+ impl Serialize for IndexItemFunctionType {
429
+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
430
+ where
431
+ S : serde:: Serializer ,
432
+ {
433
+ let mut seq = serializer. serialize_seq ( Some ( 2 ) ) ?;
434
+ let mut fn_type = String :: new ( ) ;
435
+ self . write_to_string_without_param_names ( & mut fn_type) ;
436
+ seq. serialize_element ( & fn_type) ?;
437
+
438
+ struct ParamNames < ' a > ( & ' a [ Option < Symbol > ] ) ;
439
+
440
+ impl < ' a > Serialize for ParamNames < ' a > {
441
+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
442
+ where
443
+ S : serde:: Serializer ,
444
+ {
445
+ serializer. collect_seq (
446
+ self . 0
447
+ . iter ( )
448
+ . map ( |symbol| symbol. as_ref ( ) . map ( ToString :: to_string) . unwrap_or_default ( ) ) ,
449
+ )
450
+ }
451
+ }
452
+
453
+ seq. serialize_element ( & ParamNames ( & self . param_names ) ) ?;
454
+ seq. end ( )
455
+ }
456
+ }
457
+
458
+ impl < ' de > Deserialize < ' de > for IndexItemFunctionType {
459
+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
460
+ where
461
+ D : serde:: Deserializer < ' de > ,
462
+ {
463
+ use serde:: de:: { self , Error as _} ;
464
+
465
+ struct FunctionDataVisitor ;
466
+ impl < ' de > de:: Visitor < ' de > for FunctionDataVisitor {
467
+ type Value = IndexItemFunctionType ;
468
+ fn expecting ( & self , formatter : & mut std:: fmt:: Formatter < ' _ > ) -> fmt:: Result {
469
+ write ! ( formatter, "fn data" )
470
+ }
471
+ fn visit_seq < A : de:: SeqAccess < ' de > > ( self , mut v : A ) -> Result < Self :: Value , A :: Error > {
472
+ let ( mut function_signature, _) = v
473
+ . next_element ( ) ?
474
+ . map ( |fn_ : String | {
475
+ IndexItemFunctionType :: read_from_string_without_param_names ( fn_. as_bytes ( ) )
476
+ } )
477
+ . ok_or_else ( || A :: Error :: missing_field ( "function_signature" ) ) ?;
478
+ let param_names: Vec < Option < Symbol > > = v
479
+ . next_element ( ) ?
480
+ . map ( |param_names : Vec < String > | {
481
+ param_names
482
+ . into_iter ( )
483
+ . map ( |symbol| {
484
+ if symbol. is_empty ( ) { None } else { Some ( Symbol :: intern ( & symbol) ) }
485
+ } )
486
+ . collect ( )
487
+ } )
488
+ . ok_or_else ( || A :: Error :: missing_field ( "param_names" ) ) ?;
489
+ function_signature. param_names = param_names;
490
+ Ok ( function_signature)
491
+ }
492
+ }
493
+ deserializer. deserialize_any ( FunctionDataVisitor )
494
+ }
495
+ }
496
+
426
497
#[ derive( Debug , Clone ) ]
427
498
pub ( crate ) struct StylePath {
428
499
/// The path to the theme
0 commit comments