@@ -588,7 +588,37 @@ function preLoadCss(cssUrl) {
588
588
window . register_implementors ( window . pending_implementors ) ;
589
589
}
590
590
591
- // <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code>
591
+ /**
592
+ * <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code>
593
+ *
594
+ * [RUSTDOCIMPL] type.impl
595
+ *
596
+ * This code inlines implementations into the type alias docs at runtime. It's done at
597
+ * runtime because some crates have many type aliases and many methods, and we don't want
598
+ * to generate *O*`(types*methods)` HTML text. The data inside is mostly HTML fragments,
599
+ * wrapped in JSON.
600
+ *
601
+ * - It only includes docs generated for the current crate. This function accepts an
602
+ * object mapping crate names to the set of impls.
603
+ *
604
+ * - It filters down to the set of applicable impls. The Rust type checker is used to
605
+ * tag each HTML blob with the set of type aliases that can actually use it, so the
606
+ * JS only needs to consult the attached list of type aliases.
607
+ *
608
+ * - It renames the ID attributes, to avoid conflicting IDs in the resulting DOM.
609
+ *
610
+ * - It adds the necessary items to the sidebar. If it's an inherent impl, that means
611
+ * adding methods, associated types, and associated constants. If it's a trait impl,
612
+ * that means adding it to the trait impl sidebar list.
613
+ *
614
+ * - It adds the HTML block itself. If it's an inherent impl, it goes after the type
615
+ * alias's own inherent impls. If it's a trait impl, it goes in the Trait
616
+ * Implementations section.
617
+ *
618
+ * - After processing all of the impls, it sorts the sidebar items by name.
619
+ *
620
+ * @param {{[cratename: string]: Array<Array<string|0>>} } impl
621
+ */
592
622
window . register_type_impls = imp => {
593
623
if ( ! imp || ! imp [ window . currentCrate ] ) {
594
624
return ;
@@ -625,9 +655,9 @@ function preLoadCss(cssUrl) {
625
655
"trait-implementations-list" :
626
656
"implementations-list" ;
627
657
const outputListHeaderId = isTrait ? "trait-implementations" : "implementations" ;
628
- const outputListH = document . createElement ( "h2" ) ;
629
- outputListH . id = outputListHeaderId ;
630
- outputListH . innerText = outputListName ;
658
+ const outputListHeader = document . createElement ( "h2" ) ;
659
+ outputListHeader . id = outputListHeaderId ;
660
+ outputListHeader . innerText = outputListName ;
631
661
outputList = document . createElement ( "div" ) ;
632
662
outputList . id = outputListId ;
633
663
if ( isTrait ) {
@@ -642,16 +672,16 @@ function preLoadCss(cssUrl) {
642
672
sidebarTraitList . className = "block trait-implementation" ;
643
673
sidebarSection . appendChild ( sidebarTraitList ) ;
644
674
const mainContent = document . querySelector ( "#main-content" ) ;
645
- mainContent . appendChild ( outputListH ) ;
675
+ mainContent . appendChild ( outputListHeader ) ;
646
676
mainContent . appendChild ( outputList ) ;
647
677
} else {
648
678
implementations = outputList ;
649
679
if ( trait_implementations ) {
650
- document . insertBefore ( outputListH , trait_implementations ) ;
680
+ document . insertBefore ( outputListHeader , trait_implementations ) ;
651
681
document . insertBefore ( outputList , trait_implementations ) ;
652
682
} else {
653
683
const mainContent = document . querySelector ( "#main-content" ) ;
654
- mainContent . appendChild ( outputListH ) ;
684
+ mainContent . appendChild ( outputListHeader ) ;
655
685
mainContent . appendChild ( outputList ) ;
656
686
}
657
687
}
@@ -705,20 +735,20 @@ function preLoadCss(cssUrl) {
705
735
const blockClass = hasClass ( item , "associatedtype" ) ? "associatedtype" : (
706
736
hasClass ( item , "associatedconstant" ) ? "associatedconstant" : (
707
737
"method" ) ) ;
708
- const blockH = document . createElement ( "h3" ) ;
709
- const blockA = document . createElement ( "a" ) ;
710
- blockA . href = "#implementations" ;
711
- blockA . innerText = blockTitle ;
712
- blockH . appendChild ( blockA ) ;
738
+ const blockHeader = document . createElement ( "h3" ) ;
739
+ const blockLink = document . createElement ( "a" ) ;
740
+ blockLink . href = "#implementations" ;
741
+ blockLink . innerText = blockTitle ;
742
+ blockHeader . appendChild ( blockLink ) ;
713
743
block = document . createElement ( "ul" ) ;
714
744
block . className = `block ${ blockClass } ` ;
715
745
const insertionReference = methods || sidebarTraitList ;
716
746
if ( insertionReference ) {
717
747
const insertionReferenceH = insertionReference . previousElementSibling ;
718
- sidebarSection . insertBefore ( blockH , insertionReferenceH ) ;
748
+ sidebarSection . insertBefore ( blockHeader , insertionReferenceH ) ;
719
749
sidebarSection . insertBefore ( block , insertionReferenceH ) ;
720
750
} else {
721
- sidebarSection . appendChild ( blockH ) ;
751
+ sidebarSection . appendChild ( blockHeader ) ;
722
752
sidebarSection . appendChild ( block ) ;
723
753
}
724
754
if ( hasClass ( item , "associatedtype" ) ) {
0 commit comments