@@ -640,7 +640,37 @@ function preLoadCss(cssUrl) {
640
640
window . register_implementors ( window . pending_implementors ) ;
641
641
}
642
642
643
- // <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code>
643
+ /**
644
+ * <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+type.impl&type=code>
645
+ *
646
+ * [RUSTDOCIMPL] type.impl
647
+ *
648
+ * This code inlines implementations into the type alias docs at runtime. It's done at
649
+ * runtime because some crates have many type aliases and many methods, and we don't want
650
+ * to generate *O*`(types*methods)` HTML text. The data inside is mostly HTML fragments,
651
+ * wrapped in JSON.
652
+ *
653
+ * - It only includes docs generated for the current crate. This function accepts an
654
+ * object mapping crate names to the set of impls.
655
+ *
656
+ * - It filters down to the set of applicable impls. The Rust type checker is used to
657
+ * tag each HTML blob with the set of type aliases that can actually use it, so the
658
+ * JS only needs to consult the attached list of type aliases.
659
+ *
660
+ * - It renames the ID attributes, to avoid conflicting IDs in the resulting DOM.
661
+ *
662
+ * - It adds the necessary items to the sidebar. If it's an inherent impl, that means
663
+ * adding methods, associated types, and associated constants. If it's a trait impl,
664
+ * that means adding it to the trait impl sidebar list.
665
+ *
666
+ * - It adds the HTML block itself. If it's an inherent impl, it goes after the type
667
+ * alias's own inherent impls. If it's a trait impl, it goes in the Trait
668
+ * Implementations section.
669
+ *
670
+ * - After processing all of the impls, it sorts the sidebar items by name.
671
+ *
672
+ * @param {{[cratename: string]: Array<Array<string|0>>} } impl
673
+ */
644
674
window . register_type_impls = imp => {
645
675
if ( ! imp || ! imp [ window . currentCrate ] ) {
646
676
return ;
@@ -677,9 +707,9 @@ function preLoadCss(cssUrl) {
677
707
"trait-implementations-list" :
678
708
"implementations-list" ;
679
709
const outputListHeaderId = isTrait ? "trait-implementations" : "implementations" ;
680
- const outputListH = document . createElement ( "h2" ) ;
681
- outputListH . id = outputListHeaderId ;
682
- outputListH . innerText = outputListName ;
710
+ const outputListHeader = document . createElement ( "h2" ) ;
711
+ outputListHeader . id = outputListHeaderId ;
712
+ outputListHeader . innerText = outputListName ;
683
713
outputList = document . createElement ( "div" ) ;
684
714
outputList . id = outputListId ;
685
715
if ( isTrait ) {
@@ -694,16 +724,16 @@ function preLoadCss(cssUrl) {
694
724
sidebarTraitList . className = "block trait-implementation" ;
695
725
sidebarSection . appendChild ( sidebarTraitList ) ;
696
726
const mainContent = document . querySelector ( "#main-content" ) ;
697
- mainContent . appendChild ( outputListH ) ;
727
+ mainContent . appendChild ( outputListHeader ) ;
698
728
mainContent . appendChild ( outputList ) ;
699
729
} else {
700
730
implementations = outputList ;
701
731
if ( trait_implementations ) {
702
- document . insertBefore ( outputListH , trait_implementations ) ;
732
+ document . insertBefore ( outputListHeader , trait_implementations ) ;
703
733
document . insertBefore ( outputList , trait_implementations ) ;
704
734
} else {
705
735
const mainContent = document . querySelector ( "#main-content" ) ;
706
- mainContent . appendChild ( outputListH ) ;
736
+ mainContent . appendChild ( outputListHeader ) ;
707
737
mainContent . appendChild ( outputList ) ;
708
738
}
709
739
}
@@ -757,20 +787,20 @@ function preLoadCss(cssUrl) {
757
787
const blockClass = hasClass ( item , "associatedtype" ) ? "associatedtype" : (
758
788
hasClass ( item , "associatedconstant" ) ? "associatedconstant" : (
759
789
"method" ) ) ;
760
- const blockH = document . createElement ( "h3" ) ;
761
- const blockA = document . createElement ( "a" ) ;
762
- blockA . href = "#implementations" ;
763
- blockA . innerText = blockTitle ;
764
- blockH . appendChild ( blockA ) ;
790
+ const blockHeader = document . createElement ( "h3" ) ;
791
+ const blockLink = document . createElement ( "a" ) ;
792
+ blockLink . href = "#implementations" ;
793
+ blockLink . innerText = blockTitle ;
794
+ blockHeader . appendChild ( blockLink ) ;
765
795
block = document . createElement ( "ul" ) ;
766
796
block . className = `block ${ blockClass } ` ;
767
797
const insertionReference = methods || sidebarTraitList ;
768
798
if ( insertionReference ) {
769
799
const insertionReferenceH = insertionReference . previousElementSibling ;
770
- sidebarSection . insertBefore ( blockH , insertionReferenceH ) ;
800
+ sidebarSection . insertBefore ( blockHeader , insertionReferenceH ) ;
771
801
sidebarSection . insertBefore ( block , insertionReferenceH ) ;
772
802
} else {
773
- sidebarSection . appendChild ( blockH ) ;
803
+ sidebarSection . appendChild ( blockHeader ) ;
774
804
sidebarSection . appendChild ( block ) ;
775
805
}
776
806
if ( hasClass ( item , "associatedtype" ) ) {
0 commit comments