@@ -640,7 +640,37 @@ function preLoadCss(cssUrl) {
640640 window . register_implementors ( window . pending_implementors ) ;
641641 }
642642
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+ */
644674 window . register_type_impls = imp => {
645675 if ( ! imp || ! imp [ window . currentCrate ] ) {
646676 return ;
@@ -677,9 +707,9 @@ function preLoadCss(cssUrl) {
677707 "trait-implementations-list" :
678708 "implementations-list" ;
679709 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 ;
683713 outputList = document . createElement ( "div" ) ;
684714 outputList . id = outputListId ;
685715 if ( isTrait ) {
@@ -694,16 +724,16 @@ function preLoadCss(cssUrl) {
694724 sidebarTraitList . className = "block trait-implementation" ;
695725 sidebarSection . appendChild ( sidebarTraitList ) ;
696726 const mainContent = document . querySelector ( "#main-content" ) ;
697- mainContent . appendChild ( outputListH ) ;
727+ mainContent . appendChild ( outputListHeader ) ;
698728 mainContent . appendChild ( outputList ) ;
699729 } else {
700730 implementations = outputList ;
701731 if ( trait_implementations ) {
702- document . insertBefore ( outputListH , trait_implementations ) ;
732+ document . insertBefore ( outputListHeader , trait_implementations ) ;
703733 document . insertBefore ( outputList , trait_implementations ) ;
704734 } else {
705735 const mainContent = document . querySelector ( "#main-content" ) ;
706- mainContent . appendChild ( outputListH ) ;
736+ mainContent . appendChild ( outputListHeader ) ;
707737 mainContent . appendChild ( outputList ) ;
708738 }
709739 }
@@ -757,20 +787,20 @@ function preLoadCss(cssUrl) {
757787 const blockClass = hasClass ( item , "associatedtype" ) ? "associatedtype" : (
758788 hasClass ( item , "associatedconstant" ) ? "associatedconstant" : (
759789 "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 ) ;
765795 block = document . createElement ( "ul" ) ;
766796 block . className = `block ${ blockClass } ` ;
767797 const insertionReference = methods || sidebarTraitList ;
768798 if ( insertionReference ) {
769799 const insertionReferenceH = insertionReference . previousElementSibling ;
770- sidebarSection . insertBefore ( blockH , insertionReferenceH ) ;
800+ sidebarSection . insertBefore ( blockHeader , insertionReferenceH ) ;
771801 sidebarSection . insertBefore ( block , insertionReferenceH ) ;
772802 } else {
773- sidebarSection . appendChild ( blockH ) ;
803+ sidebarSection . appendChild ( blockHeader ) ;
774804 sidebarSection . appendChild ( block ) ;
775805 }
776806 if ( hasClass ( item , "associatedtype" ) ) {
0 commit comments