1
1
use std:: ffi:: OsStr ;
2
- use std:: fmt;
3
2
use std:: fs:: { self , File } ;
4
3
use std:: io:: prelude:: * ;
5
4
use std:: io:: { self , BufReader } ;
@@ -10,6 +9,8 @@ use std::sync::LazyLock as Lazy;
10
9
use itertools:: Itertools ;
11
10
use rustc_data_structures:: flock;
12
11
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
12
+ use serde:: ser:: SerializeSeq ;
13
+ use serde:: { Serialize , Serializer } ;
13
14
14
15
use super :: { collect_paths_for_type, ensure_trailing_slash, Context , BASIC_KEYWORDS } ;
15
16
use crate :: clean:: Crate ;
@@ -563,36 +564,18 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
563
564
types : Vec < String > ,
564
565
}
565
566
566
- impl Implementor {
567
- fn to_js_string ( & self ) -> impl fmt:: Display + ' _ {
568
- fn single_quote_string ( s : & str ) -> String {
569
- let mut result = String :: with_capacity ( s. len ( ) + 2 ) ;
570
- result. push_str ( "'" ) ;
571
- for c in s. chars ( ) {
572
- if c == '"' {
573
- result. push_str ( "\" " ) ;
574
- } else {
575
- result. extend ( c. escape_default ( ) ) ;
576
- }
577
- }
578
- result. push_str ( "'" ) ;
579
- result
567
+ impl Serialize for Implementor {
568
+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
569
+ where
570
+ S : Serializer ,
571
+ {
572
+ let mut seq = serializer. serialize_seq ( None ) ?;
573
+ seq. serialize_element ( & self . text ) ?;
574
+ if self . synthetic {
575
+ seq. serialize_element ( & 1 ) ?;
576
+ seq. serialize_element ( & self . types ) ?;
580
577
}
581
- crate :: html:: format:: display_fn ( |f| {
582
- let text_esc = single_quote_string ( & self . text ) ;
583
- if self . synthetic {
584
- let types = crate :: html:: format:: comma_sep (
585
- self . types . iter ( ) . map ( |type_| single_quote_string ( type_) ) ,
586
- false ,
587
- ) ;
588
- // use `1` to represent a synthetic, because it's fewer bytes than `true`
589
- write ! ( f, "[{text_esc},1,[{types}]]" )
590
- } else {
591
- // The types list is only used for synthetic impls.
592
- // If this changes, `main.js` and `write_shared.rs` both need changed.
593
- write ! ( f, "[{text_esc}]" )
594
- }
595
- } )
578
+ seq. end ( )
596
579
}
597
580
}
598
581
@@ -626,12 +609,9 @@ if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};
626
609
}
627
610
628
611
let implementors = format ! (
629
- r#""{}":[{}] "# ,
612
+ r#""{}":{} "# ,
630
613
krate. name( cx. tcx( ) ) ,
631
- crate :: html:: format:: comma_sep(
632
- implementors. iter( ) . map( Implementor :: to_js_string) ,
633
- false
634
- )
614
+ serde_json:: to_string( & implementors) . expect( "failed serde conversion" ) ,
635
615
) ;
636
616
637
617
let mut mydst = dst. clone ( ) ;
0 commit comments