@@ -588,7 +588,37 @@ function preLoadCss(cssUrl) {
588588 window . register_implementors ( window . pending_implementors ) ;
589589 }
590590
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+ */
592622 window . register_type_impls = imp => {
593623 if ( ! imp || ! imp [ window . currentCrate ] ) {
594624 return ;
@@ -625,9 +655,9 @@ function preLoadCss(cssUrl) {
625655 "trait-implementations-list" :
626656 "implementations-list" ;
627657 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 ;
631661 outputList = document . createElement ( "div" ) ;
632662 outputList . id = outputListId ;
633663 if ( isTrait ) {
@@ -642,16 +672,16 @@ function preLoadCss(cssUrl) {
642672 sidebarTraitList . className = "block trait-implementation" ;
643673 sidebarSection . appendChild ( sidebarTraitList ) ;
644674 const mainContent = document . querySelector ( "#main-content" ) ;
645- mainContent . appendChild ( outputListH ) ;
675+ mainContent . appendChild ( outputListHeader ) ;
646676 mainContent . appendChild ( outputList ) ;
647677 } else {
648678 implementations = outputList ;
649679 if ( trait_implementations ) {
650- document . insertBefore ( outputListH , trait_implementations ) ;
680+ document . insertBefore ( outputListHeader , trait_implementations ) ;
651681 document . insertBefore ( outputList , trait_implementations ) ;
652682 } else {
653683 const mainContent = document . querySelector ( "#main-content" ) ;
654- mainContent . appendChild ( outputListH ) ;
684+ mainContent . appendChild ( outputListHeader ) ;
655685 mainContent . appendChild ( outputList ) ;
656686 }
657687 }
@@ -705,20 +735,20 @@ function preLoadCss(cssUrl) {
705735 const blockClass = hasClass ( item , "associatedtype" ) ? "associatedtype" : (
706736 hasClass ( item , "associatedconstant" ) ? "associatedconstant" : (
707737 "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 ) ;
713743 block = document . createElement ( "ul" ) ;
714744 block . className = `block ${ blockClass } ` ;
715745 const insertionReference = methods || sidebarTraitList ;
716746 if ( insertionReference ) {
717747 const insertionReferenceH = insertionReference . previousElementSibling ;
718- sidebarSection . insertBefore ( blockH , insertionReferenceH ) ;
748+ sidebarSection . insertBefore ( blockHeader , insertionReferenceH ) ;
719749 sidebarSection . insertBefore ( block , insertionReferenceH ) ;
720750 } else {
721- sidebarSection . appendChild ( blockH ) ;
751+ sidebarSection . appendChild ( blockHeader ) ;
722752 sidebarSection . appendChild ( block ) ;
723753 }
724754 if ( hasClass ( item , "associatedtype" ) ) {
0 commit comments