]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/html/static/main.js
Rollup merge of #78332 - PoignardAzur:doc_E0308, r=camelid
[rust.git] / src / librustdoc / html / static / main.js
1 // From rust:
2 /* global ALIASES, currentCrate, rootPath */
3
4 // Local js definitions:
5 /* global addClass, getCurrentValue, hasClass */
6 /* global onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
7
8 if (!String.prototype.startsWith) {
9     String.prototype.startsWith = function(searchString, position) {
10         position = position || 0;
11         return this.indexOf(searchString, position) === position;
12     };
13 }
14 if (!String.prototype.endsWith) {
15     String.prototype.endsWith = function(suffix, length) {
16         var l = length || this.length;
17         return this.indexOf(suffix, l - suffix.length) !== -1;
18     };
19 }
20
21 if (!DOMTokenList.prototype.add) {
22     DOMTokenList.prototype.add = function(className) {
23         if (className && !hasClass(this, className)) {
24             if (this.className && this.className.length > 0) {
25                 this.className += " " + className;
26             } else {
27                 this.className = className;
28             }
29         }
30     };
31 }
32
33 if (!DOMTokenList.prototype.remove) {
34     DOMTokenList.prototype.remove = function(className) {
35         if (className && this.className) {
36             this.className = (" " + this.className + " ").replace(" " + className + " ", " ")
37                                                          .trim();
38         }
39     };
40 }
41
42 function getSearchInput() {
43     return document.getElementsByClassName("search-input")[0];
44 }
45
46 function getSearchElement() {
47     return document.getElementById("search");
48 }
49
50 // Sets the focus on the search bar at the top of the page
51 function focusSearchBar() {
52     getSearchInput().focus();
53 }
54
55 // Removes the focus from the search bar
56 function defocusSearchBar() {
57     getSearchInput().blur();
58 }
59
60 (function() {
61     "use strict";
62
63     // This mapping table should match the discriminants of
64     // `rustdoc::html::item_type::ItemType` type in Rust.
65     var itemTypes = ["mod",
66                      "externcrate",
67                      "import",
68                      "struct",
69                      "enum",
70                      "fn",
71                      "type",
72                      "static",
73                      "trait",
74                      "impl",
75                      "tymethod",
76                      "method",
77                      "structfield",
78                      "variant",
79                      "macro",
80                      "primitive",
81                      "associatedtype",
82                      "constant",
83                      "associatedconstant",
84                      "union",
85                      "foreigntype",
86                      "keyword",
87                      "existential",
88                      "attr",
89                      "derive",
90                      "traitalias"];
91
92     var disableShortcuts = getCurrentValue("rustdoc-disable-shortcuts") === "true";
93     var search_input = getSearchInput();
94     var searchTimeout = null;
95     var toggleAllDocsId = "toggle-all-docs";
96
97     // On the search screen, so you remain on the last tab you opened.
98     //
99     // 0 for "In Names"
100     // 1 for "In Parameters"
101     // 2 for "In Return Types"
102     var currentTab = 0;
103
104     var mouseMovedAfterSearch = true;
105
106     var titleBeforeSearch = document.title;
107
108     function clearInputTimeout() {
109         if (searchTimeout !== null) {
110             clearTimeout(searchTimeout);
111             searchTimeout = null;
112         }
113     }
114
115     function getPageId() {
116         if (window.location.hash) {
117             var tmp = window.location.hash.replace(/^#/, "");
118             if (tmp.length > 0) {
119                 return tmp;
120             }
121         }
122         return null;
123     }
124
125     function showSidebar() {
126         var elems = document.getElementsByClassName("sidebar-elems")[0];
127         if (elems) {
128             addClass(elems, "show-it");
129         }
130         var sidebar = document.getElementsByClassName("sidebar")[0];
131         if (sidebar) {
132             addClass(sidebar, "mobile");
133             var filler = document.getElementById("sidebar-filler");
134             if (!filler) {
135                 var div = document.createElement("div");
136                 div.id = "sidebar-filler";
137                 sidebar.appendChild(div);
138             }
139         }
140         var themePickers = document.getElementsByClassName("theme-picker");
141         if (themePickers && themePickers.length > 0) {
142             themePickers[0].style.display = "none";
143         }
144     }
145
146     function hideSidebar() {
147         var elems = document.getElementsByClassName("sidebar-elems")[0];
148         if (elems) {
149             removeClass(elems, "show-it");
150         }
151         var sidebar = document.getElementsByClassName("sidebar")[0];
152         removeClass(sidebar, "mobile");
153         var filler = document.getElementById("sidebar-filler");
154         if (filler) {
155             filler.remove();
156         }
157         document.getElementsByTagName("body")[0].style.marginTop = "";
158         var themePickers = document.getElementsByClassName("theme-picker");
159         if (themePickers && themePickers.length > 0) {
160             themePickers[0].style.display = null;
161         }
162     }
163
164     function showSearchResults(search) {
165         if (search === null || typeof search === 'undefined') {
166             search = getSearchElement();
167         }
168         addClass(main, "hidden");
169         removeClass(search, "hidden");
170         mouseMovedAfterSearch = false;
171     }
172
173     function hideSearchResults(search) {
174         if (search === null || typeof search === 'undefined') {
175             search = getSearchElement();
176         }
177         addClass(search, "hidden");
178         removeClass(main, "hidden");
179     }
180
181     // used for special search precedence
182     var TY_PRIMITIVE = itemTypes.indexOf("primitive");
183     var TY_KEYWORD = itemTypes.indexOf("keyword");
184
185     function getQueryStringParams() {
186         var params = {};
187         window.location.search.substring(1).split("&").
188             map(function(s) {
189                 var pair = s.split("=");
190                 params[decodeURIComponent(pair[0])] =
191                     typeof pair[1] === "undefined" ? null : decodeURIComponent(pair[1]);
192             });
193         return params;
194     }
195
196     function browserSupportsHistoryApi() {
197         return window.history && typeof window.history.pushState === "function";
198     }
199
200     function isHidden(elem) {
201         return elem.offsetHeight === 0;
202     }
203
204     var main = document.getElementById("main");
205     var savedHash = "";
206
207     function handleHashes(ev) {
208         var elem;
209         var search = getSearchElement();
210         if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) {
211             // This block occurs when clicking on an element in the navbar while
212             // in a search.
213             hideSearchResults(search);
214             var hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1);
215             if (browserSupportsHistoryApi()) {
216                 history.replaceState(hash, "", "?search=#" + hash);
217             }
218             elem = document.getElementById(hash);
219             if (elem) {
220                 elem.scrollIntoView();
221             }
222         }
223         // This part is used in case an element is not visible.
224         if (savedHash !== window.location.hash) {
225             savedHash = window.location.hash;
226             if (savedHash.length === 0) {
227                 return;
228             }
229             elem = document.getElementById(savedHash.slice(1)); // we remove the '#'
230             if (!elem || !isHidden(elem)) {
231                 return;
232             }
233             var parent = elem.parentNode;
234             if (parent && hasClass(parent, "impl-items")) {
235                 // In case this is a trait implementation item, we first need to toggle
236                 // the "Show hidden undocumented items".
237                 onEachLazy(parent.getElementsByClassName("collapsed"), function(e) {
238                     if (e.parentNode === parent) {
239                         // Only click on the toggle we're looking for.
240                         e.click();
241                         return true;
242                     }
243                 });
244                 if (isHidden(elem)) {
245                     // The whole parent is collapsed. We need to click on its toggle as well!
246                     if (hasClass(parent.lastElementChild, "collapse-toggle")) {
247                         parent.lastElementChild.click();
248                     }
249                 }
250             }
251         }
252     }
253
254     function highlightSourceLines(match, ev) {
255         if (typeof match === "undefined") {
256             // If we're in mobile mode, we should hide the sidebar in any case.
257             hideSidebar();
258             match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
259         }
260         if (!match) {
261             return;
262         }
263         var from = parseInt(match[1], 10);
264         var to = from;
265         if (typeof match[2] !== "undefined") {
266             to = parseInt(match[2], 10);
267         }
268         if (to < from) {
269             var tmp = to;
270             to = from;
271             from = tmp;
272         }
273         var elem = document.getElementById(from);
274         if (!elem) {
275             return;
276         }
277         if (!ev) {
278             var x = document.getElementById(from);
279             if (x) {
280                 x.scrollIntoView();
281             }
282         }
283         onEachLazy(document.getElementsByClassName("line-numbers"), function(e) {
284             onEachLazy(e.getElementsByTagName("span"), function(i_e) {
285                 removeClass(i_e, "line-highlighted");
286             });
287         });
288         for (var i = from; i <= to; ++i) {
289             elem = document.getElementById(i);
290             if (!elem) {
291                 break;
292             }
293             addClass(elem, "line-highlighted");
294         }
295     }
296
297     function onHashChange(ev) {
298         // If we're in mobile mode, we should hide the sidebar in any case.
299         hideSidebar();
300         var match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
301         if (match) {
302             return highlightSourceLines(match, ev);
303         }
304         handleHashes(ev);
305     }
306
307     function expandSection(id) {
308         var elem = document.getElementById(id);
309         if (elem && isHidden(elem)) {
310             var h3 = elem.parentNode.previousElementSibling;
311             if (h3 && h3.tagName !== "H3") {
312                 h3 = h3.previousElementSibling; // skip div.docblock
313             }
314
315             if (h3) {
316                 var collapses = h3.getElementsByClassName("collapse-toggle");
317                 if (collapses.length > 0) {
318                     // The element is not visible, we need to make it appear!
319                     collapseDocs(collapses[0], "show");
320                 }
321             }
322         }
323     }
324
325     // Gets the human-readable string for the virtual-key code of the
326     // given KeyboardEvent, ev.
327     //
328     // This function is meant as a polyfill for KeyboardEvent#key,
329     // since it is not supported in Trident.  We also test for
330     // KeyboardEvent#keyCode because the handleShortcut handler is
331     // also registered for the keydown event, because Blink doesn't fire
332     // keypress on hitting the Escape key.
333     //
334     // So I guess you could say things are getting pretty interoperable.
335     function getVirtualKey(ev) {
336         if ("key" in ev && typeof ev.key != "undefined") {
337             return ev.key;
338         }
339
340         var c = ev.charCode || ev.keyCode;
341         if (c == 27) {
342             return "Escape";
343         }
344         return String.fromCharCode(c);
345     }
346
347     function getHelpElement() {
348         buildHelperPopup();
349         return document.getElementById("help");
350     }
351
352     function displayHelp(display, ev, help) {
353         help = help ? help : getHelpElement();
354         if (display === true) {
355             if (hasClass(help, "hidden")) {
356                 ev.preventDefault();
357                 removeClass(help, "hidden");
358                 addClass(document.body, "blur");
359             }
360         } else if (hasClass(help, "hidden") === false) {
361             ev.preventDefault();
362             addClass(help, "hidden");
363             removeClass(document.body, "blur");
364         }
365     }
366
367     function handleEscape(ev) {
368         var help = getHelpElement();
369         var search = getSearchElement();
370         if (hasClass(help, "hidden") === false) {
371             displayHelp(false, ev, help);
372         } else if (hasClass(search, "hidden") === false) {
373             clearInputTimeout();
374             ev.preventDefault();
375             hideSearchResults(search);
376             document.title = titleBeforeSearch;
377         }
378         defocusSearchBar();
379     }
380
381     function handleShortcut(ev) {
382         // Don't interfere with browser shortcuts
383         if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts === true) {
384             return;
385         }
386
387         if (document.activeElement.tagName === "INPUT") {
388             switch (getVirtualKey(ev)) {
389             case "Escape":
390                 handleEscape(ev);
391                 break;
392             }
393         } else {
394             switch (getVirtualKey(ev)) {
395             case "Escape":
396                 handleEscape(ev);
397                 break;
398
399             case "s":
400             case "S":
401                 displayHelp(false, ev);
402                 ev.preventDefault();
403                 focusSearchBar();
404                 break;
405
406             case "+":
407             case "-":
408                 ev.preventDefault();
409                 toggleAllDocs();
410                 break;
411
412             case "?":
413                 displayHelp(true, ev);
414                 break;
415             }
416         }
417     }
418
419     function findParentElement(elem, tagName) {
420         do {
421             if (elem && elem.tagName === tagName) {
422                 return elem;
423             }
424             elem = elem.parentNode;
425         } while (elem);
426         return null;
427     }
428
429     document.addEventListener("keypress", handleShortcut);
430     document.addEventListener("keydown", handleShortcut);
431
432     function resetMouseMoved(ev) {
433         mouseMovedAfterSearch = true;
434     }
435
436     document.addEventListener("mousemove", resetMouseMoved);
437
438     var handleSourceHighlight = (function() {
439         var prev_line_id = 0;
440
441         var set_fragment = function(name) {
442             var x = window.scrollX,
443                 y = window.scrollY;
444             if (browserSupportsHistoryApi()) {
445                 history.replaceState(null, null, "#" + name);
446                 highlightSourceLines();
447             } else {
448                 location.replace("#" + name);
449             }
450             // Prevent jumps when selecting one or many lines
451             window.scrollTo(x, y);
452         };
453
454         return function(ev) {
455             var cur_line_id = parseInt(ev.target.id, 10);
456             ev.preventDefault();
457
458             if (ev.shiftKey && prev_line_id) {
459                 // Swap selection if needed
460                 if (prev_line_id > cur_line_id) {
461                     var tmp = prev_line_id;
462                     prev_line_id = cur_line_id;
463                     cur_line_id = tmp;
464                 }
465
466                 set_fragment(prev_line_id + "-" + cur_line_id);
467             } else {
468                 prev_line_id = cur_line_id;
469
470                 set_fragment(cur_line_id);
471             }
472         };
473     }());
474
475     document.addEventListener("click", function(ev) {
476         if (hasClass(ev.target, "help-button")) {
477             displayHelp(true, ev);
478         } else if (hasClass(ev.target, "collapse-toggle")) {
479             collapseDocs(ev.target, "toggle");
480         } else if (hasClass(ev.target.parentNode, "collapse-toggle")) {
481             collapseDocs(ev.target.parentNode, "toggle");
482         } else if (ev.target.tagName === "SPAN" && hasClass(ev.target.parentNode, "line-numbers")) {
483             handleSourceHighlight(ev);
484         } else if (hasClass(getHelpElement(), "hidden") === false) {
485             var help = getHelpElement();
486             var is_inside_help_popup = ev.target !== help && help.contains(ev.target);
487             if (is_inside_help_popup === false) {
488                 addClass(help, "hidden");
489                 removeClass(document.body, "blur");
490             }
491         } else {
492             // Making a collapsed element visible on onhashchange seems
493             // too late
494             var a = findParentElement(ev.target, "A");
495             if (a && a.hash) {
496                 expandSection(a.hash.replace(/^#/, ""));
497             }
498         }
499     });
500
501     (function() {
502         var x = document.getElementsByClassName("version-selector");
503         if (x.length > 0) {
504             x[0].onchange = function() {
505                 var i, match,
506                     url = document.location.href,
507                     stripped = "",
508                     len = rootPath.match(/\.\.\//g).length + 1;
509
510                 for (i = 0; i < len; ++i) {
511                     match = url.match(/\/[^\/]*$/);
512                     if (i < len - 1) {
513                         stripped = match[0] + stripped;
514                     }
515                     url = url.substring(0, url.length - match[0].length);
516                 }
517
518                 var selectedVersion = document.getElementsByClassName("version-selector")[0].value;
519                 url += "/" + selectedVersion + stripped;
520
521                 document.location.href = url;
522             };
523         }
524     }());
525
526     /**
527      * A function to compute the Levenshtein distance between two strings
528      * Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported
529      * Full License can be found at http://creativecommons.org/licenses/by-sa/3.0/legalcode
530      * This code is an unmodified version of the code written by Marco de Wit
531      * and was found at http://stackoverflow.com/a/18514751/745719
532      */
533     var levenshtein_row2 = [];
534     function levenshtein(s1, s2) {
535         if (s1 === s2) {
536             return 0;
537         }
538         var s1_len = s1.length, s2_len = s2.length;
539         if (s1_len && s2_len) {
540             var i1 = 0, i2 = 0, a, b, c, c2, row = levenshtein_row2;
541             while (i1 < s1_len) {
542                 row[i1] = ++i1;
543             }
544             while (i2 < s2_len) {
545                 c2 = s2.charCodeAt(i2);
546                 a = i2;
547                 ++i2;
548                 b = i2;
549                 for (i1 = 0; i1 < s1_len; ++i1) {
550                     c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0);
551                     a = row[i1];
552                     b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c);
553                     row[i1] = b;
554                 }
555             }
556             return b;
557         }
558         return s1_len + s2_len;
559     }
560
561     window.initSearch = function(rawSearchIndex) {
562         var MAX_LEV_DISTANCE = 3;
563         var MAX_RESULTS = 200;
564         var GENERICS_DATA = 1;
565         var NAME = 0;
566         var INPUTS_DATA = 0;
567         var OUTPUT_DATA = 1;
568         var NO_TYPE_FILTER = -1;
569         var currentResults, index, searchIndex;
570         var ALIASES = {};
571         var params = getQueryStringParams();
572
573         // Populate search bar with query string search term when provided,
574         // but only if the input bar is empty. This avoid the obnoxious issue
575         // where you start trying to do a search, and the index loads, and
576         // suddenly your search is gone!
577         if (search_input.value === "") {
578             search_input.value = params.search || "";
579         }
580
581         /**
582          * Executes the query and builds an index of results
583          * @param  {[Object]} query      [The user query]
584          * @param  {[type]} searchWords  [The list of search words to query
585          *                                against]
586          * @param  {[type]} filterCrates [Crate to search in if defined]
587          * @return {[type]}              [A search index of results]
588          */
589         function execQuery(query, searchWords, filterCrates) {
590             function itemTypeFromName(typename) {
591                 var length = itemTypes.length;
592                 for (var i = 0; i < length; ++i) {
593                     if (itemTypes[i] === typename) {
594                         return i;
595                     }
596                 }
597                 return NO_TYPE_FILTER;
598             }
599
600             var valLower = query.query.toLowerCase(),
601                 val = valLower,
602                 typeFilter = itemTypeFromName(query.type),
603                 results = {}, results_in_args = {}, results_returned = {},
604                 split = valLower.split("::");
605
606             var length = split.length;
607             for (var z = 0; z < length; ++z) {
608                 if (split[z] === "") {
609                     split.splice(z, 1);
610                     z -= 1;
611                 }
612             }
613
614             function transformResults(results, isType) {
615                 var out = [];
616                 var length = results.length;
617                 for (var i = 0; i < length; ++i) {
618                     if (results[i].id > -1) {
619                         var obj = searchIndex[results[i].id];
620                         obj.lev = results[i].lev;
621                         if (isType !== true || obj.type) {
622                             var res = buildHrefAndPath(obj);
623                             obj.displayPath = pathSplitter(res[0]);
624                             obj.fullPath = obj.displayPath + obj.name;
625                             // To be sure than it some items aren't considered as duplicate.
626                             obj.fullPath += "|" + obj.ty;
627                             obj.href = res[1];
628                             out.push(obj);
629                             if (out.length >= MAX_RESULTS) {
630                                 break;
631                             }
632                         }
633                     }
634                 }
635                 return out;
636             }
637
638             function sortResults(results, isType) {
639                 var ar = [];
640                 for (var entry in results) {
641                     if (hasOwnProperty(results, entry)) {
642                         ar.push(results[entry]);
643                     }
644                 }
645                 results = ar;
646                 var i;
647                 var nresults = results.length;
648                 for (i = 0; i < nresults; ++i) {
649                     results[i].word = searchWords[results[i].id];
650                     results[i].item = searchIndex[results[i].id] || {};
651                 }
652                 // if there are no results then return to default and fail
653                 if (results.length === 0) {
654                     return [];
655                 }
656
657                 results.sort(function(aaa, bbb) {
658                     var a, b;
659
660                     // sort by exact match with regard to the last word (mismatch goes later)
661                     a = (aaa.word !== val);
662                     b = (bbb.word !== val);
663                     if (a !== b) { return a - b; }
664
665                     // Sort by non levenshtein results and then levenshtein results by the distance
666                     // (less changes required to match means higher rankings)
667                     a = (aaa.lev);
668                     b = (bbb.lev);
669                     if (a !== b) { return a - b; }
670
671                     // sort by crate (non-current crate goes later)
672                     a = (aaa.item.crate !== window.currentCrate);
673                     b = (bbb.item.crate !== window.currentCrate);
674                     if (a !== b) { return a - b; }
675
676                     // sort by item name length (longer goes later)
677                     a = aaa.word.length;
678                     b = bbb.word.length;
679                     if (a !== b) { return a - b; }
680
681                     // sort by item name (lexicographically larger goes later)
682                     a = aaa.word;
683                     b = bbb.word;
684                     if (a !== b) { return (a > b ? +1 : -1); }
685
686                     // sort by index of keyword in item name (no literal occurrence goes later)
687                     a = (aaa.index < 0);
688                     b = (bbb.index < 0);
689                     if (a !== b) { return a - b; }
690                     // (later literal occurrence, if any, goes later)
691                     a = aaa.index;
692                     b = bbb.index;
693                     if (a !== b) { return a - b; }
694
695                     // special precedence for primitive and keyword pages
696                     if ((aaa.item.ty === TY_PRIMITIVE && bbb.item.ty !== TY_KEYWORD) ||
697                         (aaa.item.ty === TY_KEYWORD && bbb.item.ty !== TY_PRIMITIVE)) {
698                         return -1;
699                     }
700                     if ((bbb.item.ty === TY_PRIMITIVE && aaa.item.ty !== TY_PRIMITIVE) ||
701                         (bbb.item.ty === TY_KEYWORD && aaa.item.ty !== TY_KEYWORD)) {
702                         return 1;
703                     }
704
705                     // sort by description (no description goes later)
706                     a = (aaa.item.desc === "");
707                     b = (bbb.item.desc === "");
708                     if (a !== b) { return a - b; }
709
710                     // sort by type (later occurrence in `itemTypes` goes later)
711                     a = aaa.item.ty;
712                     b = bbb.item.ty;
713                     if (a !== b) { return a - b; }
714
715                     // sort by path (lexicographically larger goes later)
716                     a = aaa.item.path;
717                     b = bbb.item.path;
718                     if (a !== b) { return (a > b ? +1 : -1); }
719
720                     // que sera, sera
721                     return 0;
722                 });
723
724                 var length = results.length;
725                 for (i = 0; i < length; ++i) {
726                     var result = results[i];
727
728                     // this validation does not make sense when searching by types
729                     if (result.dontValidate) {
730                         continue;
731                     }
732                     var name = result.item.name.toLowerCase(),
733                         path = result.item.path.toLowerCase(),
734                         parent = result.item.parent;
735
736                     if (isType !== true &&
737                         validateResult(name, path, split, parent) === false)
738                     {
739                         result.id = -1;
740                     }
741                 }
742                 return transformResults(results);
743             }
744
745             function extractGenerics(val) {
746                 val = val.toLowerCase();
747                 if (val.indexOf("<") !== -1) {
748                     var values = val.substring(val.indexOf("<") + 1, val.lastIndexOf(">"));
749                     return {
750                         name: val.substring(0, val.indexOf("<")),
751                         generics: values.split(/\s*,\s*/),
752                     };
753                 }
754                 return {
755                     name: val,
756                     generics: [],
757                 };
758             }
759
760             function getObjectFromId(id) {
761                 if (typeof id === "number") {
762                     return searchIndex[id];
763                 }
764                 return {'name': id};
765             }
766
767             function checkGenerics(obj, val) {
768                 // The names match, but we need to be sure that all generics kinda
769                 // match as well.
770                 var lev_distance = MAX_LEV_DISTANCE + 1;
771                 if (val.generics.length > 0) {
772                     if (obj.length > GENERICS_DATA &&
773                           obj[GENERICS_DATA].length >= val.generics.length) {
774                         var elems = obj[GENERICS_DATA].slice(0);
775                         var total = 0;
776                         var done = 0;
777                         // We need to find the type that matches the most to remove it in order
778                         // to move forward.
779                         var vlength = val.generics.length;
780                         for (var y = 0; y < vlength; ++y) {
781                             var lev = { pos: -1, lev: MAX_LEV_DISTANCE + 1};
782                             var elength = elems.length;
783                             var firstGeneric = getObjectFromId(val.generics[y]).name;
784                             for (var x = 0; x < elength; ++x) {
785                                 var tmp_lev = levenshtein(getObjectFromId(elems[x]).name,
786                                                           firstGeneric);
787                                 if (tmp_lev < lev.lev) {
788                                     lev.lev = tmp_lev;
789                                     lev.pos = x;
790                                 }
791                             }
792                             if (lev.pos !== -1) {
793                                 elems.splice(lev.pos, 1);
794                                 lev_distance = Math.min(lev.lev, lev_distance);
795                                 total += lev.lev;
796                                 done += 1;
797                             } else {
798                                 return MAX_LEV_DISTANCE + 1;
799                             }
800                         }
801                         return Math.ceil(total / done);
802                     }
803                 }
804                 return MAX_LEV_DISTANCE + 1;
805             }
806
807             // Check for type name and type generics (if any).
808             function checkType(obj, val, literalSearch) {
809                 var lev_distance = MAX_LEV_DISTANCE + 1;
810                 var x;
811                 if (obj[NAME] === val.name) {
812                     if (literalSearch === true) {
813                         if (val.generics && val.generics.length !== 0) {
814                             if (obj.length > GENERICS_DATA &&
815                                   obj[GENERICS_DATA].length >= val.generics.length) {
816                                 var elems = obj[GENERICS_DATA].slice(0);
817                                 var allFound = true;
818
819                                 for (var y = 0; allFound === true && y < val.generics.length; ++y) {
820                                     allFound = false;
821                                     var firstGeneric = getObjectFromId(val.generics[y]).name;
822                                     for (x = 0; allFound === false && x < elems.length; ++x) {
823                                         allFound = getObjectFromId(elems[x]).name === firstGeneric;
824                                     }
825                                     if (allFound === true) {
826                                         elems.splice(x - 1, 1);
827                                     }
828                                 }
829                                 if (allFound === true) {
830                                     return true;
831                                 }
832                             } else {
833                                 return false;
834                             }
835                         }
836                         return true;
837                     }
838                     // If the type has generics but don't match, then it won't return at this point.
839                     // Otherwise, `checkGenerics` will return 0 and it'll return.
840                     if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length !== 0) {
841                         var tmp_lev = checkGenerics(obj, val);
842                         if (tmp_lev <= MAX_LEV_DISTANCE) {
843                             return tmp_lev;
844                         }
845                     } else {
846                         return 0;
847                     }
848                 }
849                 // Names didn't match so let's check if one of the generic types could.
850                 if (literalSearch === true) {
851                      if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) {
852                         var length = obj[GENERICS_DATA].length;
853                         for (x = 0; x < length; ++x) {
854                             if (obj[GENERICS_DATA][x] === val.name) {
855                                 return true;
856                             }
857                         }
858                     }
859                     return false;
860                 }
861                 lev_distance = Math.min(levenshtein(obj[NAME], val.name), lev_distance);
862                 if (lev_distance <= MAX_LEV_DISTANCE) {
863                     // The generics didn't match but the name kinda did so we give it
864                     // a levenshtein distance value that isn't *this* good so it goes
865                     // into the search results but not too high.
866                     lev_distance = Math.ceil((checkGenerics(obj, val) + lev_distance) / 2);
867                 } else if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) {
868                     // We can check if the type we're looking for is inside the generics!
869                     var olength = obj[GENERICS_DATA].length;
870                     for (x = 0; x < olength; ++x) {
871                         lev_distance = Math.min(levenshtein(obj[GENERICS_DATA][x], val.name),
872                                                 lev_distance);
873                     }
874                 }
875                 // Now whatever happens, the returned distance is "less good" so we should mark it
876                 // as such, and so we add 1 to the distance to make it "less good".
877                 return lev_distance + 1;
878             }
879
880             function findArg(obj, val, literalSearch, typeFilter) {
881                 var lev_distance = MAX_LEV_DISTANCE + 1;
882
883                 if (obj && obj.type && obj.type[INPUTS_DATA] && obj.type[INPUTS_DATA].length > 0) {
884                     var length = obj.type[INPUTS_DATA].length;
885                     for (var i = 0; i < length; i++) {
886                         var tmp = obj.type[INPUTS_DATA][i];
887                         if (typePassesFilter(typeFilter, tmp[1]) === false) {
888                             continue;
889                         }
890                         tmp = checkType(tmp, val, literalSearch);
891                         if (literalSearch === true) {
892                             if (tmp === true) {
893                                 return true;
894                             }
895                             continue;
896                         }
897                         lev_distance = Math.min(tmp, lev_distance);
898                         if (lev_distance === 0) {
899                             return 0;
900                         }
901                     }
902                 }
903                 return literalSearch === true ? false : lev_distance;
904             }
905
906             function checkReturned(obj, val, literalSearch, typeFilter) {
907                 var lev_distance = MAX_LEV_DISTANCE + 1;
908
909                 if (obj && obj.type && obj.type.length > OUTPUT_DATA) {
910                     var ret = obj.type[OUTPUT_DATA];
911                     if (typeof ret[0] === "string") {
912                         ret = [ret];
913                     }
914                     for (var x = 0; x < ret.length; ++x) {
915                         var tmp = ret[x];
916                         if (typePassesFilter(typeFilter, tmp[1]) === false) {
917                             continue;
918                         }
919                         tmp = checkType(tmp, val, literalSearch);
920                         if (literalSearch === true) {
921                             if (tmp === true) {
922                                 return true;
923                             }
924                             continue;
925                         }
926                         lev_distance = Math.min(tmp, lev_distance);
927                         if (lev_distance === 0) {
928                             return 0;
929                         }
930                     }
931                 }
932                 return literalSearch === true ? false : lev_distance;
933             }
934
935             function checkPath(contains, lastElem, ty) {
936                 if (contains.length === 0) {
937                     return 0;
938                 }
939                 var ret_lev = MAX_LEV_DISTANCE + 1;
940                 var path = ty.path.split("::");
941
942                 if (ty.parent && ty.parent.name) {
943                     path.push(ty.parent.name.toLowerCase());
944                 }
945
946                 var length = path.length;
947                 var clength = contains.length;
948                 if (clength > length) {
949                     return MAX_LEV_DISTANCE + 1;
950                 }
951                 for (var i = 0; i < length; ++i) {
952                     if (i + clength > length) {
953                         break;
954                     }
955                     var lev_total = 0;
956                     var aborted = false;
957                     for (var x = 0; x < clength; ++x) {
958                         var lev = levenshtein(path[i + x], contains[x]);
959                         if (lev > MAX_LEV_DISTANCE) {
960                             aborted = true;
961                             break;
962                         }
963                         lev_total += lev;
964                     }
965                     if (aborted === false) {
966                         ret_lev = Math.min(ret_lev, Math.round(lev_total / clength));
967                     }
968                 }
969                 return ret_lev;
970             }
971
972             function typePassesFilter(filter, type) {
973                 // No filter
974                 if (filter <= NO_TYPE_FILTER) return true;
975
976                 // Exact match
977                 if (filter === type) return true;
978
979                 // Match related items
980                 var name = itemTypes[type];
981                 switch (itemTypes[filter]) {
982                     case "constant":
983                         return name === "associatedconstant";
984                     case "fn":
985                         return name === "method" || name === "tymethod";
986                     case "type":
987                         return name === "primitive" || name === "associatedtype";
988                     case "trait":
989                         return name === "traitalias";
990                 }
991
992                 // No match
993                 return false;
994             }
995
996             function generateId(ty) {
997                 if (ty.parent && ty.parent.name) {
998                     return itemTypes[ty.ty] + ty.path + ty.parent.name + ty.name;
999                 }
1000                 return itemTypes[ty.ty] + ty.path + ty.name;
1001             }
1002
1003             function createAliasFromItem(item) {
1004                 return {
1005                     crate: item.crate,
1006                     name: item.name,
1007                     path: item.path,
1008                     desc: item.desc,
1009                     ty: item.ty,
1010                     parent: item.parent,
1011                     type: item.type,
1012                     is_alias: true,
1013                 };
1014             }
1015
1016             function handleAliases(ret, query, filterCrates) {
1017                 // We separate aliases and crate aliases because we want to have current crate
1018                 // aliases to be before the others in the displayed results.
1019                 var aliases = [];
1020                 var crateAliases = [];
1021                 var i;
1022                 if (filterCrates !== undefined) {
1023                     if (ALIASES[filterCrates] && ALIASES[filterCrates][query.search]) {
1024                         for (i = 0; i < ALIASES[filterCrates][query.search].length; ++i) {
1025                             aliases.push(
1026                                 createAliasFromItem(
1027                                     searchIndex[ALIASES[filterCrates][query.search][i]]));
1028                         }
1029                     }
1030                 } else {
1031                     Object.keys(ALIASES).forEach(function(crate) {
1032                         if (ALIASES[crate][query.search]) {
1033                             var pushTo = crate === window.currentCrate ? crateAliases : aliases;
1034                             for (i = 0; i < ALIASES[crate][query.search].length; ++i) {
1035                                 pushTo.push(
1036                                     createAliasFromItem(
1037                                         searchIndex[ALIASES[crate][query.search][i]]));
1038                             }
1039                         }
1040                     });
1041                 }
1042
1043                 var sortFunc = function(aaa, bbb) {
1044                     if (aaa.path < bbb.path) {
1045                         return 1;
1046                     } else if (aaa.path === bbb.path) {
1047                         return 0;
1048                     }
1049                     return -1;
1050                 };
1051                 crateAliases.sort(sortFunc);
1052                 aliases.sort(sortFunc);
1053
1054                 var pushFunc = function(alias) {
1055                     alias.alias = query.raw;
1056                     var res = buildHrefAndPath(alias);
1057                     alias.displayPath = pathSplitter(res[0]);
1058                     alias.fullPath = alias.displayPath + alias.name;
1059                     alias.href = res[1];
1060
1061                     ret.others.unshift(alias);
1062                     if (ret.others.length > MAX_RESULTS) {
1063                         ret.others.pop();
1064                     }
1065                 };
1066                 onEach(aliases, pushFunc);
1067                 onEach(crateAliases, pushFunc);
1068             }
1069
1070             // quoted values mean literal search
1071             var nSearchWords = searchWords.length;
1072             var i;
1073             var ty;
1074             var fullId;
1075             var returned;
1076             var in_args;
1077             if ((val.charAt(0) === "\"" || val.charAt(0) === "'") &&
1078                 val.charAt(val.length - 1) === val.charAt(0))
1079             {
1080                 val = extractGenerics(val.substr(1, val.length - 2));
1081                 for (i = 0; i < nSearchWords; ++i) {
1082                     if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) {
1083                         continue;
1084                     }
1085                     in_args = findArg(searchIndex[i], val, true, typeFilter);
1086                     returned = checkReturned(searchIndex[i], val, true, typeFilter);
1087                     ty = searchIndex[i];
1088                     fullId = generateId(ty);
1089
1090                     if (searchWords[i] === val.name
1091                         && typePassesFilter(typeFilter, searchIndex[i].ty)
1092                         && results[fullId] === undefined) {
1093                         results[fullId] = {
1094                             id: i,
1095                             index: -1,
1096                             dontValidate: true,
1097                         };
1098                     }
1099                     if (in_args === true && results_in_args[fullId] === undefined) {
1100                         results_in_args[fullId] = {
1101                             id: i,
1102                             index: -1,
1103                             dontValidate: true,
1104                         };
1105                     }
1106                     if (returned === true && results_returned[fullId] === undefined) {
1107                         results_returned[fullId] = {
1108                             id: i,
1109                             index: -1,
1110                             dontValidate: true,
1111                         };
1112                     }
1113                 }
1114                 query.inputs = [val];
1115                 query.output = val;
1116                 query.search = val;
1117             // searching by type
1118             } else if (val.search("->") > -1) {
1119                 var trimmer = function(s) { return s.trim(); };
1120                 var parts = val.split("->").map(trimmer);
1121                 var input = parts[0];
1122                 // sort inputs so that order does not matter
1123                 var inputs = input.split(",").map(trimmer).sort();
1124                 for (i = 0; i < inputs.length; ++i) {
1125                     inputs[i] = extractGenerics(inputs[i]);
1126                 }
1127                 var output = extractGenerics(parts[1]);
1128
1129                 for (i = 0; i < nSearchWords; ++i) {
1130                     if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) {
1131                         continue;
1132                     }
1133                     var type = searchIndex[i].type;
1134                     ty = searchIndex[i];
1135                     if (!type) {
1136                         continue;
1137                     }
1138                     fullId = generateId(ty);
1139
1140                     returned = checkReturned(ty, output, true, NO_TYPE_FILTER);
1141                     if (output.name === "*" || returned === true) {
1142                         in_args = false;
1143                         var is_module = false;
1144
1145                         if (input === "*") {
1146                             is_module = true;
1147                         } else {
1148                             var allFound = true;
1149                             for (var it = 0; allFound === true && it < inputs.length; it++) {
1150                                 allFound = checkType(type, inputs[it], true);
1151                             }
1152                             in_args = allFound;
1153                         }
1154                         if (in_args === true) {
1155                             results_in_args[fullId] = {
1156                                 id: i,
1157                                 index: -1,
1158                                 dontValidate: true,
1159                             };
1160                         }
1161                         if (returned === true) {
1162                             results_returned[fullId] = {
1163                                 id: i,
1164                                 index: -1,
1165                                 dontValidate: true,
1166                             };
1167                         }
1168                         if (is_module === true) {
1169                             results[fullId] = {
1170                                 id: i,
1171                                 index: -1,
1172                                 dontValidate: true,
1173                             };
1174                         }
1175                     }
1176                 }
1177                 query.inputs = inputs.map(function(input) {
1178                     return input.name;
1179                 });
1180                 query.output = output.name;
1181             } else {
1182                 query.inputs = [val];
1183                 query.output = val;
1184                 query.search = val;
1185                 // gather matching search results up to a certain maximum
1186                 val = val.replace(/\_/g, "");
1187
1188                 var valGenerics = extractGenerics(val);
1189
1190                 var paths = valLower.split("::");
1191                 var j;
1192                 for (j = 0; j < paths.length; ++j) {
1193                     if (paths[j] === "") {
1194                         paths.splice(j, 1);
1195                         j -= 1;
1196                     }
1197                 }
1198                 val = paths[paths.length - 1];
1199                 var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1);
1200
1201                 var lev;
1202                 for (j = 0; j < nSearchWords; ++j) {
1203                     ty = searchIndex[j];
1204                     if (!ty || (filterCrates !== undefined && ty.crate !== filterCrates)) {
1205                         continue;
1206                     }
1207                     var lev_add = 0;
1208                     if (paths.length > 1) {
1209                         lev = checkPath(contains, paths[paths.length - 1], ty);
1210                         if (lev > MAX_LEV_DISTANCE) {
1211                             continue;
1212                         } else if (lev > 0) {
1213                             lev_add = lev / 10;
1214                         }
1215                     }
1216
1217                     returned = MAX_LEV_DISTANCE + 1;
1218                     in_args = MAX_LEV_DISTANCE + 1;
1219                     var index = -1;
1220                     // we want lev results to go lower than others
1221                     lev = MAX_LEV_DISTANCE + 1;
1222                     fullId = generateId(ty);
1223
1224                     if (searchWords[j].indexOf(split[i]) > -1 ||
1225                         searchWords[j].indexOf(val) > -1 ||
1226                         searchWords[j].replace(/_/g, "").indexOf(val) > -1)
1227                     {
1228                         // filter type: ... queries
1229                         if (typePassesFilter(typeFilter, ty.ty) && results[fullId] === undefined) {
1230                             index = searchWords[j].replace(/_/g, "").indexOf(val);
1231                         }
1232                     }
1233                     if ((lev = levenshtein(searchWords[j], val)) <= MAX_LEV_DISTANCE) {
1234                         if (typePassesFilter(typeFilter, ty.ty) === false) {
1235                             lev = MAX_LEV_DISTANCE + 1;
1236                         } else {
1237                             lev += 1;
1238                         }
1239                     }
1240                     in_args = findArg(ty, valGenerics, false, typeFilter);
1241                     returned = checkReturned(ty, valGenerics, false, typeFilter);
1242
1243                     lev += lev_add;
1244                     if (lev > 0 && val.length > 3 && searchWords[j].indexOf(val) > -1) {
1245                         if (val.length < 6) {
1246                             lev -= 1;
1247                         } else {
1248                             lev = 0;
1249                         }
1250                     }
1251                     if (in_args <= MAX_LEV_DISTANCE) {
1252                         if (results_in_args[fullId] === undefined) {
1253                             results_in_args[fullId] = {
1254                                 id: j,
1255                                 index: index,
1256                                 lev: in_args,
1257                             };
1258                         }
1259                         results_in_args[fullId].lev =
1260                             Math.min(results_in_args[fullId].lev, in_args);
1261                     }
1262                     if (returned <= MAX_LEV_DISTANCE) {
1263                         if (results_returned[fullId] === undefined) {
1264                             results_returned[fullId] = {
1265                                 id: j,
1266                                 index: index,
1267                                 lev: returned,
1268                             };
1269                         }
1270                         results_returned[fullId].lev =
1271                             Math.min(results_returned[fullId].lev, returned);
1272                     }
1273                     if (index !== -1 || lev <= MAX_LEV_DISTANCE) {
1274                         if (index !== -1 && paths.length < 2) {
1275                             lev = 0;
1276                         }
1277                         if (results[fullId] === undefined) {
1278                             results[fullId] = {
1279                                 id: j,
1280                                 index: index,
1281                                 lev: lev,
1282                             };
1283                         }
1284                         results[fullId].lev = Math.min(results[fullId].lev, lev);
1285                     }
1286                 }
1287             }
1288
1289             var ret = {
1290                 "in_args": sortResults(results_in_args, true),
1291                 "returned": sortResults(results_returned, true),
1292                 "others": sortResults(results),
1293             };
1294             handleAliases(ret, query, filterCrates);
1295             return ret;
1296         }
1297
1298         /**
1299          * Validate performs the following boolean logic. For example:
1300          * "File::open" will give IF A PARENT EXISTS => ("file" && "open")
1301          * exists in (name || path || parent) OR => ("file" && "open") exists in
1302          * (name || path )
1303          *
1304          * This could be written functionally, but I wanted to minimise
1305          * functions on stack.
1306          *
1307          * @param  {[string]} name   [The name of the result]
1308          * @param  {[string]} path   [The path of the result]
1309          * @param  {[string]} keys   [The keys to be used (["file", "open"])]
1310          * @param  {[object]} parent [The parent of the result]
1311          * @return {[boolean]}       [Whether the result is valid or not]
1312          */
1313         function validateResult(name, path, keys, parent) {
1314             for (var i = 0; i < keys.length; ++i) {
1315                 // each check is for validation so we negate the conditions and invalidate
1316                 if (!(
1317                     // check for an exact name match
1318                     name.indexOf(keys[i]) > -1 ||
1319                     // then an exact path match
1320                     path.indexOf(keys[i]) > -1 ||
1321                     // next if there is a parent, check for exact parent match
1322                     (parent !== undefined && parent.name !== undefined &&
1323                         parent.name.toLowerCase().indexOf(keys[i]) > -1) ||
1324                     // lastly check to see if the name was a levenshtein match
1325                     levenshtein(name, keys[i]) <= MAX_LEV_DISTANCE)) {
1326                     return false;
1327                 }
1328             }
1329             return true;
1330         }
1331
1332         function getQuery(raw) {
1333             var matches, type, query;
1334             query = raw;
1335
1336             matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i);
1337             if (matches) {
1338                 type = matches[1].replace(/^const$/, "constant");
1339                 query = query.substring(matches[0].length);
1340             }
1341
1342             return {
1343                 raw: raw,
1344                 query: query,
1345                 type: type,
1346                 id: query + type
1347             };
1348         }
1349
1350         function initSearchNav() {
1351             var hoverTimeout;
1352
1353             var click_func = function(e) {
1354                 var el = e.target;
1355                 // to retrieve the real "owner" of the event.
1356                 while (el.tagName !== "TR") {
1357                     el = el.parentNode;
1358                 }
1359                 var dst = e.target.getElementsByTagName("a");
1360                 if (dst.length < 1) {
1361                     return;
1362                 }
1363                 dst = dst[0];
1364                 if (window.location.pathname === dst.pathname) {
1365                     hideSearchResults();
1366                     document.location.href = dst.href;
1367                 }
1368             };
1369             var mouseover_func = function(e) {
1370                 if (mouseMovedAfterSearch) {
1371                     var el = e.target;
1372                     // to retrieve the real "owner" of the event.
1373                     while (el.tagName !== "TR") {
1374                         el = el.parentNode;
1375                     }
1376                     clearTimeout(hoverTimeout);
1377                     hoverTimeout = setTimeout(function() {
1378                         onEachLazy(document.getElementsByClassName("search-results"), function(e) {
1379                             onEachLazy(e.getElementsByClassName("result"), function(i_e) {
1380                                 removeClass(i_e, "highlighted");
1381                             });
1382                         });
1383                         addClass(el, "highlighted");
1384                     }, 20);
1385                 }
1386             };
1387             onEachLazy(document.getElementsByClassName("search-results"), function(e) {
1388                 onEachLazy(e.getElementsByClassName("result"), function(i_e) {
1389                     i_e.onclick = click_func;
1390                     i_e.onmouseover = mouseover_func;
1391                 });
1392             });
1393
1394             search_input.onkeydown = function(e) {
1395                 // "actives" references the currently highlighted item in each search tab.
1396                 // Each array in "actives" represents a tab.
1397                 var actives = [[], [], []];
1398                 // "current" is used to know which tab we're looking into.
1399                 var current = 0;
1400                 onEachLazy(document.getElementById("results").childNodes, function(e) {
1401                     onEachLazy(e.getElementsByClassName("highlighted"), function(h_e) {
1402                         actives[current].push(h_e);
1403                     });
1404                     current += 1;
1405                 });
1406
1407                 if (e.which === 38) { // up
1408                     if (!actives[currentTab].length ||
1409                         !actives[currentTab][0].previousElementSibling) {
1410                         return;
1411                     }
1412
1413                     addClass(actives[currentTab][0].previousElementSibling, "highlighted");
1414                     removeClass(actives[currentTab][0], "highlighted");
1415                     e.preventDefault();
1416                 } else if (e.which === 40) { // down
1417                     if (!actives[currentTab].length) {
1418                         var results = document.getElementById("results").childNodes;
1419                         if (results.length > 0) {
1420                             var res = results[currentTab].getElementsByClassName("result");
1421                             if (res.length > 0) {
1422                                 addClass(res[0], "highlighted");
1423                             }
1424                         }
1425                     } else if (actives[currentTab][0].nextElementSibling) {
1426                         addClass(actives[currentTab][0].nextElementSibling, "highlighted");
1427                         removeClass(actives[currentTab][0], "highlighted");
1428                     }
1429                     e.preventDefault();
1430                 } else if (e.which === 13) { // return
1431                     if (actives[currentTab].length) {
1432                         document.location.href =
1433                             actives[currentTab][0].getElementsByTagName("a")[0].href;
1434                     }
1435                 } else if (e.which === 9) { // tab
1436                     if (e.shiftKey) {
1437                         printTab(currentTab > 0 ? currentTab - 1 : 2);
1438                     } else {
1439                         printTab(currentTab > 1 ? 0 : currentTab + 1);
1440                     }
1441                     e.preventDefault();
1442                 } else if (e.which === 16) { // shift
1443                     // Does nothing, it's just to avoid losing "focus" on the highlighted element.
1444                 } else if (actives[currentTab].length > 0) {
1445                     removeClass(actives[currentTab][0], "highlighted");
1446                 }
1447             };
1448         }
1449
1450         function buildHrefAndPath(item) {
1451             var displayPath;
1452             var href;
1453             var type = itemTypes[item.ty];
1454             var name = item.name;
1455             var path = item.path;
1456
1457             if (type === "mod") {
1458                 displayPath = path + "::";
1459                 href = rootPath + path.replace(/::/g, "/") + "/" +
1460                        name + "/index.html";
1461             } else if (type === "primitive" || type === "keyword") {
1462                 displayPath = "";
1463                 href = rootPath + path.replace(/::/g, "/") +
1464                        "/" + type + "." + name + ".html";
1465             } else if (type === "externcrate") {
1466                 displayPath = "";
1467                 href = rootPath + name + "/index.html";
1468             } else if (item.parent !== undefined) {
1469                 var myparent = item.parent;
1470                 var anchor = "#" + type + "." + name;
1471                 var parentType = itemTypes[myparent.ty];
1472                 var pageType = parentType;
1473                 var pageName = myparent.name;
1474
1475                 if (parentType === "primitive") {
1476                     displayPath = myparent.name + "::";
1477                 } else if (type === "structfield" && parentType === "variant") {
1478                     // Structfields belonging to variants are special: the
1479                     // final path element is the enum name.
1480                     var splitPath = item.path.split("::");
1481                     var enumName = splitPath.pop();
1482                     path = splitPath.join("::");
1483                     displayPath = path + "::" + enumName + "::" + myparent.name + "::";
1484                     anchor = "#variant." + myparent.name + ".field." + name;
1485                     pageType = "enum";
1486                     pageName = enumName;
1487                 } else {
1488                     displayPath = path + "::" + myparent.name + "::";
1489                 }
1490                 href = rootPath + path.replace(/::/g, "/") +
1491                        "/" + pageType +
1492                        "." + pageName +
1493                        ".html" + anchor;
1494             } else {
1495                 displayPath = item.path + "::";
1496                 href = rootPath + item.path.replace(/::/g, "/") +
1497                        "/" + type + "." + name + ".html";
1498             }
1499             return [displayPath, href];
1500         }
1501
1502         function escape(content) {
1503             var h1 = document.createElement("h1");
1504             h1.textContent = content;
1505             return h1.innerHTML;
1506         }
1507
1508         function pathSplitter(path) {
1509             var tmp = "<span>" + path.replace(/::/g, "::</span><span>");
1510             if (tmp.endsWith("<span>")) {
1511                 return tmp.slice(0, tmp.length - 6);
1512             }
1513             return tmp;
1514         }
1515
1516         function addTab(array, query, display) {
1517             var extraStyle = "";
1518             if (display === false) {
1519                 extraStyle = " style=\"display: none;\"";
1520             }
1521
1522             var output = "";
1523             var duplicates = {};
1524             var length = 0;
1525             if (array.length > 0) {
1526                 output = "<table class=\"search-results\"" + extraStyle + ">";
1527
1528                 array.forEach(function(item) {
1529                     var name, type;
1530
1531                     name = item.name;
1532                     type = itemTypes[item.ty];
1533
1534                     if (item.is_alias !== true) {
1535                         if (duplicates[item.fullPath]) {
1536                             return;
1537                         }
1538                         duplicates[item.fullPath] = true;
1539                     }
1540                     length += 1;
1541
1542                     output += "<tr class=\"" + type + " result\"><td>" +
1543                               "<a href=\"" + item.href + "\">" +
1544                               (item.is_alias === true ?
1545                                ("<span class=\"alias\"><b>" + item.alias + " </b></span><span " +
1546                                   "class=\"grey\"><i>&nbsp;- see&nbsp;</i></span>") : "") +
1547                               item.displayPath + "<span class=\"" + type + "\">" +
1548                               name + "</span></a></td><td>" +
1549                               "<a href=\"" + item.href + "\">" +
1550                               "<span class=\"desc\">" + escape(item.desc) +
1551                               "&nbsp;</span></a></td></tr>";
1552                 });
1553                 output += "</table>";
1554             } else {
1555                 output = "<div class=\"search-failed\"" + extraStyle + ">No results :(<br/>" +
1556                     "Try on <a href=\"https://duckduckgo.com/?q=" +
1557                     encodeURIComponent("rust " + query.query) +
1558                     "\">DuckDuckGo</a>?<br/><br/>" +
1559                     "Or try looking in one of these:<ul><li>The <a " +
1560                     "href=\"https://doc.rust-lang.org/reference/index.html\">Rust Reference</a> " +
1561                     " for technical details about the language.</li><li><a " +
1562                     "href=\"https://doc.rust-lang.org/rust-by-example/index.html\">Rust By " +
1563                     "Example</a> for expository code examples.</a></li><li>The <a " +
1564                     "href=\"https://doc.rust-lang.org/book/index.html\">Rust Book</a> for " +
1565                     "introductions to language features and the language itself.</li><li><a " +
1566                     "href=\"https://docs.rs\">Docs.rs</a> for documentation of crates released on" +
1567                     " <a href=\"https://crates.io/\">crates.io</a>.</li></ul></div>";
1568             }
1569             return [output, length];
1570         }
1571
1572         function makeTabHeader(tabNb, text, nbElems) {
1573             if (currentTab === tabNb) {
1574                 return "<div class=\"selected\">" + text +
1575                        " <div class=\"count\">(" + nbElems + ")</div></div>";
1576             }
1577             return "<div>" + text + " <div class=\"count\">(" + nbElems + ")</div></div>";
1578         }
1579
1580         function showResults(results) {
1581             var search = getSearchElement();
1582             if (results.others.length === 1
1583                 && getCurrentValue("rustdoc-go-to-only-result") === "true"
1584                 // By default, the search DOM element is "empty" (meaning it has no children not
1585                 // text content). Once a search has been run, it won't be empty, even if you press
1586                 // ESC or empty the search input (which also "cancels" the search).
1587                 && (!search.firstChild || search.firstChild.innerText !== getSearchLoadingText()))
1588             {
1589                 var elem = document.createElement("a");
1590                 elem.href = results.others[0].href;
1591                 elem.style.display = "none";
1592                 // For firefox, we need the element to be in the DOM so it can be clicked.
1593                 document.body.appendChild(elem);
1594                 elem.click();
1595                 return;
1596             }
1597             var query = getQuery(search_input.value);
1598
1599             currentResults = query.id;
1600
1601             var ret_others = addTab(results.others, query);
1602             var ret_in_args = addTab(results.in_args, query, false);
1603             var ret_returned = addTab(results.returned, query, false);
1604
1605             var output = "<h1>Results for " + escape(query.query) +
1606                 (query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
1607                 "<div id=\"titles\">" +
1608                 makeTabHeader(0, "In Names", ret_others[1]) +
1609                 makeTabHeader(1, "In Parameters", ret_in_args[1]) +
1610                 makeTabHeader(2, "In Return Types", ret_returned[1]) +
1611                 "</div><div id=\"results\">" +
1612                 ret_others[0] + ret_in_args[0] + ret_returned[0] + "</div>";
1613
1614             search.innerHTML = output;
1615             showSearchResults(search);
1616             var tds = search.getElementsByTagName("td");
1617             var td_width = 0;
1618             if (tds.length > 0) {
1619                 td_width = tds[0].offsetWidth;
1620             }
1621             var width = search.offsetWidth - 40 - td_width;
1622             onEachLazy(search.getElementsByClassName("desc"), function(e) {
1623                 e.style.width = width + "px";
1624             });
1625             initSearchNav();
1626             var elems = document.getElementById("titles").childNodes;
1627             elems[0].onclick = function() { printTab(0); };
1628             elems[1].onclick = function() { printTab(1); };
1629             elems[2].onclick = function() { printTab(2); };
1630             printTab(currentTab);
1631         }
1632
1633         function execSearch(query, searchWords, filterCrates) {
1634             function getSmallest(arrays, positions, notDuplicates) {
1635                 var start = null;
1636
1637                 for (var it = 0; it < positions.length; ++it) {
1638                     if (arrays[it].length > positions[it] &&
1639                         (start === null || start > arrays[it][positions[it]].lev) &&
1640                         !notDuplicates[arrays[it][positions[it]].fullPath]) {
1641                         start = arrays[it][positions[it]].lev;
1642                     }
1643                 }
1644                 return start;
1645             }
1646
1647             function mergeArrays(arrays) {
1648                 var ret = [];
1649                 var positions = [];
1650                 var notDuplicates = {};
1651
1652                 for (var x = 0; x < arrays.length; ++x) {
1653                     positions.push(0);
1654                 }
1655                 while (ret.length < MAX_RESULTS) {
1656                     var smallest = getSmallest(arrays, positions, notDuplicates);
1657
1658                     if (smallest === null) {
1659                         break;
1660                     }
1661                     for (x = 0; x < arrays.length && ret.length < MAX_RESULTS; ++x) {
1662                         if (arrays[x].length > positions[x] &&
1663                                 arrays[x][positions[x]].lev === smallest &&
1664                                 !notDuplicates[arrays[x][positions[x]].fullPath]) {
1665                             ret.push(arrays[x][positions[x]]);
1666                             notDuplicates[arrays[x][positions[x]].fullPath] = true;
1667                             positions[x] += 1;
1668                         }
1669                     }
1670                 }
1671                 return ret;
1672             }
1673
1674             var queries = query.raw.split(",");
1675             var results = {
1676                 "in_args": [],
1677                 "returned": [],
1678                 "others": [],
1679             };
1680
1681             for (var i = 0; i < queries.length; ++i) {
1682                 query = queries[i].trim();
1683                 if (query.length !== 0) {
1684                     var tmp = execQuery(getQuery(query), searchWords, filterCrates);
1685
1686                     results.in_args.push(tmp.in_args);
1687                     results.returned.push(tmp.returned);
1688                     results.others.push(tmp.others);
1689                 }
1690             }
1691             if (queries.length > 1) {
1692                 return {
1693                     "in_args": mergeArrays(results.in_args),
1694                     "returned": mergeArrays(results.returned),
1695                     "others": mergeArrays(results.others),
1696                 };
1697             }
1698             return {
1699                 "in_args": results.in_args[0],
1700                 "returned": results.returned[0],
1701                 "others": results.others[0],
1702             };
1703         }
1704
1705         function getFilterCrates() {
1706             var elem = document.getElementById("crate-search");
1707
1708             if (elem && elem.value !== "All crates" && hasOwnProperty(rawSearchIndex, elem.value)) {
1709                 return elem.value;
1710             }
1711             return undefined;
1712         }
1713
1714         function search(e, forced) {
1715             var params = getQueryStringParams();
1716             var query = getQuery(search_input.value.trim());
1717
1718             if (e) {
1719                 e.preventDefault();
1720             }
1721
1722             if (query.query.length === 0) {
1723                 return;
1724             }
1725             if (forced !== true && query.id === currentResults) {
1726                 if (query.query.length > 0) {
1727                     putBackSearch(search_input);
1728                 }
1729                 return;
1730             }
1731
1732             // Update document title to maintain a meaningful browser history
1733             document.title = "Results for " + query.query + " - Rust";
1734
1735             // Because searching is incremental by character, only the most
1736             // recent search query is added to the browser history.
1737             if (browserSupportsHistoryApi()) {
1738                 if (!history.state && !params.search) {
1739                     history.pushState(query, "", "?search=" + encodeURIComponent(query.raw));
1740                 } else {
1741                     history.replaceState(query, "", "?search=" + encodeURIComponent(query.raw));
1742                 }
1743             }
1744
1745             var filterCrates = getFilterCrates();
1746             showResults(execSearch(query, index, filterCrates));
1747         }
1748
1749         function buildIndex(rawSearchIndex) {
1750             searchIndex = [];
1751             var searchWords = [];
1752             var i;
1753             var currentIndex = 0;
1754
1755             for (var crate in rawSearchIndex) {
1756                 if (!hasOwnProperty(rawSearchIndex, crate)) { continue; }
1757
1758                 var crateSize = 0;
1759
1760                 searchWords.push(crate);
1761                 searchIndex.push({
1762                     crate: crate,
1763                     ty: 1, // == ExternCrate
1764                     name: crate,
1765                     path: "",
1766                     desc: rawSearchIndex[crate].doc,
1767                     type: null,
1768                 });
1769                 currentIndex += 1;
1770
1771                 // an array of [(Number) item type,
1772                 //              (String) name,
1773                 //              (String) full path or empty string for previous path,
1774                 //              (String) description,
1775                 //              (Number | null) the parent path index to `paths`]
1776                 //              (Object | null) the type of the function (if any)
1777                 var items = rawSearchIndex[crate].i;
1778                 // an array of [(Number) item type,
1779                 //              (String) name]
1780                 var paths = rawSearchIndex[crate].p;
1781                 // a array of [(String) alias name
1782                 //             [Number] index to items]
1783                 var aliases = rawSearchIndex[crate].a;
1784
1785                 // convert `rawPaths` entries into object form
1786                 var len = paths.length;
1787                 for (i = 0; i < len; ++i) {
1788                     paths[i] = {ty: paths[i][0], name: paths[i][1]};
1789                 }
1790
1791                 // convert `items` into an object form, and construct word indices.
1792                 //
1793                 // before any analysis is performed lets gather the search terms to
1794                 // search against apart from the rest of the data.  This is a quick
1795                 // operation that is cached for the life of the page state so that
1796                 // all other search operations have access to this cached data for
1797                 // faster analysis operations
1798                 len = items.length;
1799                 var lastPath = "";
1800                 for (i = 0; i < len; ++i) {
1801                     var rawRow = items[i];
1802                     if (!rawRow[2]) {
1803                         rawRow[2] = lastPath;
1804                     }
1805                     var row = {
1806                         crate: crate,
1807                         ty: rawRow[0],
1808                         name: rawRow[1],
1809                         path: rawRow[2],
1810                         desc: rawRow[3],
1811                         parent: paths[rawRow[4]],
1812                         type: rawRow[5],
1813                     };
1814                     searchIndex.push(row);
1815                     if (typeof row.name === "string") {
1816                         var word = row.name.toLowerCase();
1817                         searchWords.push(word);
1818                     } else {
1819                         searchWords.push("");
1820                     }
1821                     lastPath = row.path;
1822                     crateSize += 1;
1823                 }
1824
1825                 if (aliases) {
1826                     ALIASES[crate] = {};
1827                     var j, local_aliases;
1828                     for (var alias_name in aliases) {
1829                         if (!aliases.hasOwnProperty(alias_name)) { continue; }
1830
1831                         if (!ALIASES[crate].hasOwnProperty(alias_name)) {
1832                             ALIASES[crate][alias_name] = [];
1833                         }
1834                         local_aliases = aliases[alias_name];
1835                         for (j = 0; j < local_aliases.length; ++j) {
1836                             ALIASES[crate][alias_name].push(local_aliases[j] + currentIndex);
1837                         }
1838                     }
1839                 }
1840                 currentIndex += crateSize;
1841             }
1842             return searchWords;
1843         }
1844
1845         function startSearch() {
1846             var callback = function() {
1847                 clearInputTimeout();
1848                 if (search_input.value.length === 0) {
1849                     if (browserSupportsHistoryApi()) {
1850                         history.replaceState("", window.currentCrate + " - Rust", "?search=");
1851                     }
1852                     hideSearchResults();
1853                 } else {
1854                     searchTimeout = setTimeout(search, 500);
1855                 }
1856             };
1857             search_input.onkeyup = callback;
1858             search_input.oninput = callback;
1859             document.getElementsByClassName("search-form")[0].onsubmit = function(e) {
1860                 e.preventDefault();
1861                 clearInputTimeout();
1862                 search();
1863             };
1864             search_input.onchange = function(e) {
1865                 if (e.target !== document.activeElement) {
1866                     // To prevent doing anything when it's from a blur event.
1867                     return;
1868                 }
1869                 // Do NOT e.preventDefault() here. It will prevent pasting.
1870                 clearInputTimeout();
1871                 // zero-timeout necessary here because at the time of event handler execution the
1872                 // pasted content is not in the input field yet. Shouldn’t make any difference for
1873                 // change, though.
1874                 setTimeout(search, 0);
1875             };
1876             search_input.onpaste = search_input.onchange;
1877
1878             var selectCrate = document.getElementById("crate-search");
1879             if (selectCrate) {
1880                 selectCrate.onchange = function() {
1881                     updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value);
1882                     search(undefined, true);
1883                 };
1884             }
1885
1886             // Push and pop states are used to add search results to the browser
1887             // history.
1888             if (browserSupportsHistoryApi()) {
1889                 // Store the previous <title> so we can revert back to it later.
1890                 var previousTitle = document.title;
1891
1892                 window.addEventListener("popstate", function(e) {
1893                     var params = getQueryStringParams();
1894                     // Revert to the previous title manually since the History
1895                     // API ignores the title parameter.
1896                     document.title = previousTitle;
1897                     // When browsing forward to search results the previous
1898                     // search will be repeated, so the currentResults are
1899                     // cleared to ensure the search is successful.
1900                     currentResults = null;
1901                     // Synchronize search bar with query string state and
1902                     // perform the search. This will empty the bar if there's
1903                     // nothing there, which lets you really go back to a
1904                     // previous state with nothing in the bar.
1905                     if (params.search && params.search.length > 0) {
1906                         search_input.value = params.search;
1907                         // Some browsers fire "onpopstate" for every page load
1908                         // (Chrome), while others fire the event only when actually
1909                         // popping a state (Firefox), which is why search() is
1910                         // called both here and at the end of the startSearch()
1911                         // function.
1912                         search(e);
1913                     } else {
1914                         search_input.value = "";
1915                         // When browsing back from search results the main page
1916                         // visibility must be reset.
1917                         hideSearchResults();
1918                     }
1919                 });
1920             }
1921             search();
1922         }
1923
1924         index = buildIndex(rawSearchIndex);
1925         startSearch();
1926
1927         // Draw a convenient sidebar of known crates if we have a listing
1928         if (rootPath === "../" || rootPath === "./") {
1929             var sidebar = document.getElementsByClassName("sidebar-elems")[0];
1930             if (sidebar) {
1931                 var div = document.createElement("div");
1932                 div.className = "block crate";
1933                 div.innerHTML = "<h3>Crates</h3>";
1934                 var ul = document.createElement("ul");
1935                 div.appendChild(ul);
1936
1937                 var crates = [];
1938                 for (var crate in rawSearchIndex) {
1939                     if (!hasOwnProperty(rawSearchIndex, crate)) {
1940                         continue;
1941                     }
1942                     crates.push(crate);
1943                 }
1944                 crates.sort();
1945                 for (var i = 0; i < crates.length; ++i) {
1946                     var klass = "crate";
1947                     if (rootPath !== "./" && crates[i] === window.currentCrate) {
1948                         klass += " current";
1949                     }
1950                     var link = document.createElement("a");
1951                     link.href = rootPath + crates[i] + "/index.html";
1952                     link.title = rawSearchIndex[crates[i]].doc;
1953                     link.className = klass;
1954                     link.textContent = crates[i];
1955
1956                     var li = document.createElement("li");
1957                     li.appendChild(link);
1958                     ul.appendChild(li);
1959                 }
1960                 sidebar.appendChild(div);
1961             }
1962         }
1963     };
1964
1965
1966     // delayed sidebar rendering.
1967     window.initSidebarItems = function(items) {
1968         var sidebar = document.getElementsByClassName("sidebar-elems")[0];
1969         var current = window.sidebarCurrent;
1970
1971         function block(shortty, longty) {
1972             var filtered = items[shortty];
1973             if (!filtered) {
1974                 return;
1975             }
1976
1977             var div = document.createElement("div");
1978             div.className = "block " + shortty;
1979             var h3 = document.createElement("h3");
1980             h3.textContent = longty;
1981             div.appendChild(h3);
1982             var ul = document.createElement("ul");
1983
1984             var length = filtered.length;
1985             for (var i = 0; i < length; ++i) {
1986                 var item = filtered[i];
1987                 var name = item[0];
1988                 var desc = item[1]; // can be null
1989
1990                 var klass = shortty;
1991                 if (name === current.name && shortty === current.ty) {
1992                     klass += " current";
1993                 }
1994                 var path;
1995                 if (shortty === "mod") {
1996                     path = name + "/index.html";
1997                 } else {
1998                     path = shortty + "." + name + ".html";
1999                 }
2000                 var link = document.createElement("a");
2001                 link.href = current.relpath + path;
2002                 link.title = desc;
2003                 link.className = klass;
2004                 link.textContent = name;
2005                 var li = document.createElement("li");
2006                 li.appendChild(link);
2007                 ul.appendChild(li);
2008             }
2009             div.appendChild(ul);
2010             if (sidebar) {
2011                 sidebar.appendChild(div);
2012             }
2013         }
2014
2015         block("primitive", "Primitive Types");
2016         block("mod", "Modules");
2017         block("macro", "Macros");
2018         block("struct", "Structs");
2019         block("enum", "Enums");
2020         block("union", "Unions");
2021         block("constant", "Constants");
2022         block("static", "Statics");
2023         block("trait", "Traits");
2024         block("fn", "Functions");
2025         block("type", "Type Definitions");
2026         block("foreigntype", "Foreign Types");
2027         block("keyword", "Keywords");
2028         block("traitalias", "Trait Aliases");
2029     };
2030
2031     window.register_implementors = function(imp) {
2032         var implementors = document.getElementById("implementors-list");
2033         var synthetic_implementors = document.getElementById("synthetic-implementors-list");
2034
2035         if (synthetic_implementors) {
2036             // This `inlined_types` variable is used to avoid having the same implementation
2037             // showing up twice. For example "String" in the "Sync" doc page.
2038             //
2039             // By the way, this is only used by and useful for traits implemented automatically
2040             // (like "Send" and "Sync").
2041             var inlined_types = new Set();
2042             onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) {
2043                 var aliases = el.getAttribute("aliases");
2044                 if (!aliases) {
2045                     return;
2046                 }
2047                 aliases.split(",").forEach(function(alias) {
2048                     inlined_types.add(alias);
2049                 });
2050             });
2051         }
2052
2053         var libs = Object.getOwnPropertyNames(imp);
2054         var llength = libs.length;
2055         for (var i = 0; i < llength; ++i) {
2056             if (libs[i] === currentCrate) { continue; }
2057             var structs = imp[libs[i]];
2058
2059             var slength = structs.length;
2060             struct_loop:
2061             for (var j = 0; j < slength; ++j) {
2062                 var struct = structs[j];
2063
2064                 var list = struct.synthetic ? synthetic_implementors : implementors;
2065
2066                 if (struct.synthetic) {
2067                     var stlength = struct.types.length;
2068                     for (var k = 0; k < stlength; k++) {
2069                         if (inlined_types.has(struct.types[k])) {
2070                             continue struct_loop;
2071                         }
2072                         inlined_types.add(struct.types[k]);
2073                     }
2074                 }
2075
2076                 var code = document.createElement("code");
2077                 code.innerHTML = struct.text;
2078
2079                 var x = code.getElementsByTagName("a");
2080                 var xlength = x.length;
2081                 for (var it = 0; it < xlength; it++) {
2082                     var href = x[it].getAttribute("href");
2083                     if (href && href.indexOf("http") !== 0) {
2084                         x[it].setAttribute("href", rootPath + href);
2085                     }
2086                 }
2087                 var display = document.createElement("h3");
2088                 addClass(display, "impl");
2089                 display.innerHTML = "<span class=\"in-band\"><table class=\"table-display\">" +
2090                     "<tbody><tr><td><code>" + code.outerHTML + "</code></td><td></td></tr>" +
2091                     "</tbody></table></span>";
2092                 list.appendChild(display);
2093             }
2094         }
2095     };
2096     if (window.pending_implementors) {
2097         window.register_implementors(window.pending_implementors);
2098     }
2099
2100     function labelForToggleButton(sectionIsCollapsed) {
2101         if (sectionIsCollapsed) {
2102             // button will expand the section
2103             return "+";
2104         }
2105         // button will collapse the section
2106         // note that this text is also set in the HTML template in render.rs
2107         return "\u2212"; // "\u2212" is "−" minus sign
2108     }
2109
2110     function onEveryMatchingChild(elem, className, func) {
2111         if (elem && className && func) {
2112             var length = elem.childNodes.length;
2113             var nodes = elem.childNodes;
2114             for (var i = 0; i < length; ++i) {
2115                 if (hasClass(nodes[i], className)) {
2116                     func(nodes[i]);
2117                 } else {
2118                     onEveryMatchingChild(nodes[i], className, func);
2119                 }
2120             }
2121         }
2122     }
2123
2124     function toggleAllDocs(pageId, fromAutoCollapse) {
2125         var innerToggle = document.getElementById(toggleAllDocsId);
2126         if (!innerToggle) {
2127             return;
2128         }
2129         if (hasClass(innerToggle, "will-expand")) {
2130             updateLocalStorage("rustdoc-collapse", "false");
2131             removeClass(innerToggle, "will-expand");
2132             onEveryMatchingChild(innerToggle, "inner", function(e) {
2133                 e.innerHTML = labelForToggleButton(false);
2134             });
2135             innerToggle.title = "collapse all docs";
2136             if (fromAutoCollapse !== true) {
2137                 onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
2138                     collapseDocs(e, "show");
2139                 });
2140             }
2141         } else {
2142             updateLocalStorage("rustdoc-collapse", "true");
2143             addClass(innerToggle, "will-expand");
2144             onEveryMatchingChild(innerToggle, "inner", function(e) {
2145                 var parent = e.parentNode;
2146                 var superParent = null;
2147
2148                 if (parent) {
2149                     superParent = parent.parentNode;
2150                 }
2151                 if (!parent || !superParent || superParent.id !== "main" ||
2152                     hasClass(parent, "impl") === false) {
2153                     e.innerHTML = labelForToggleButton(true);
2154                 }
2155             });
2156             innerToggle.title = "expand all docs";
2157             if (fromAutoCollapse !== true) {
2158                 onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
2159                     var parent = e.parentNode;
2160                     var superParent = null;
2161
2162                     if (parent) {
2163                         superParent = parent.parentNode;
2164                     }
2165                     if (!parent || !superParent || superParent.id !== "main" ||
2166                         hasClass(parent, "impl") === false) {
2167                         collapseDocs(e, "hide", pageId);
2168                     }
2169                 });
2170             }
2171         }
2172     }
2173
2174     function collapseDocs(toggle, mode, pageId) {
2175         if (!toggle || !toggle.parentNode) {
2176             return;
2177         }
2178
2179         function adjustToggle(arg) {
2180             return function(e) {
2181                 if (hasClass(e, "toggle-label")) {
2182                     if (arg) {
2183                         e.style.display = "inline-block";
2184                     } else {
2185                         e.style.display = "none";
2186                     }
2187                 }
2188                 if (hasClass(e, "inner")) {
2189                     e.innerHTML = labelForToggleButton(arg);
2190                 }
2191             };
2192         }
2193
2194         function implHider(addOrRemove, fullHide) {
2195             return function(n) {
2196                 var is_method = hasClass(n, "method") || fullHide;
2197                 if (is_method || hasClass(n, "type")) {
2198                     if (is_method === true) {
2199                         if (addOrRemove) {
2200                             addClass(n, "hidden-by-impl-hider");
2201                         } else {
2202                             removeClass(n, "hidden-by-impl-hider");
2203                         }
2204                     }
2205                     var ns = n.nextElementSibling;
2206                     while (ns && (hasClass(ns, "docblock") || hasClass(ns, "stability"))) {
2207                         if (addOrRemove) {
2208                             addClass(ns, "hidden-by-impl-hider");
2209                         } else {
2210                             removeClass(ns, "hidden-by-impl-hider");
2211                         }
2212                         ns = ns.nextElementSibling;
2213                     }
2214                 }
2215             };
2216         }
2217
2218         var relatedDoc;
2219         var action = mode;
2220         if (hasClass(toggle.parentNode, "impl") === false) {
2221             relatedDoc = toggle.parentNode.nextElementSibling;
2222             if (hasClass(relatedDoc, "stability")) {
2223                 relatedDoc = relatedDoc.nextElementSibling;
2224             }
2225             if (hasClass(relatedDoc, "docblock") || hasClass(relatedDoc, "sub-variant")) {
2226                 if (mode === "toggle") {
2227                     if (hasClass(relatedDoc, "hidden-by-usual-hider")) {
2228                         action = "show";
2229                     } else {
2230                         action = "hide";
2231                     }
2232                 }
2233                 if (action === "hide") {
2234                     addClass(relatedDoc, "hidden-by-usual-hider");
2235                     onEachLazy(toggle.childNodes, adjustToggle(true));
2236                     addClass(toggle.parentNode, "collapsed");
2237                 } else if (action === "show") {
2238                     removeClass(relatedDoc, "hidden-by-usual-hider");
2239                     removeClass(toggle.parentNode, "collapsed");
2240                     onEachLazy(toggle.childNodes, adjustToggle(false));
2241                 }
2242             }
2243         } else {
2244             // we are collapsing the impl block(s).
2245
2246             var parentElem = toggle.parentNode;
2247             relatedDoc = parentElem;
2248             var docblock = relatedDoc.nextElementSibling;
2249
2250             while (hasClass(relatedDoc, "impl-items") === false) {
2251                 relatedDoc = relatedDoc.nextElementSibling;
2252             }
2253
2254             if (!relatedDoc && hasClass(docblock, "docblock") === false) {
2255                 return;
2256             }
2257
2258             // Hide all functions, but not associated types/consts.
2259
2260             if (mode === "toggle") {
2261                 if (hasClass(relatedDoc, "fns-now-collapsed") ||
2262                     hasClass(docblock, "hidden-by-impl-hider")) {
2263                     action = "show";
2264                 } else {
2265                     action = "hide";
2266                 }
2267             }
2268
2269             var dontApplyBlockRule = toggle.parentNode.parentNode.id !== "main";
2270             if (action === "show") {
2271                 removeClass(relatedDoc, "fns-now-collapsed");
2272                 removeClass(docblock, "hidden-by-usual-hider");
2273                 onEachLazy(toggle.childNodes, adjustToggle(false, dontApplyBlockRule));
2274                 onEachLazy(relatedDoc.childNodes, implHider(false, dontApplyBlockRule));
2275             } else if (action === "hide") {
2276                 addClass(relatedDoc, "fns-now-collapsed");
2277                 addClass(docblock, "hidden-by-usual-hider");
2278                 onEachLazy(toggle.childNodes, adjustToggle(true, dontApplyBlockRule));
2279                 onEachLazy(relatedDoc.childNodes, implHider(true, dontApplyBlockRule));
2280             }
2281         }
2282     }
2283
2284     function collapser(pageId, e, collapse) {
2285         // inherent impl ids are like "impl" or impl-<number>'.
2286         // they will never be hidden by default.
2287         var n = e.parentElement;
2288         if (n.id.match(/^impl(?:-\d+)?$/) === null) {
2289             // Automatically minimize all non-inherent impls
2290             if (collapse || hasClass(n, "impl")) {
2291                 collapseDocs(e, "hide", pageId);
2292             }
2293         }
2294     }
2295
2296     function autoCollapse(pageId, collapse) {
2297         if (collapse) {
2298             toggleAllDocs(pageId, true);
2299         } else if (getCurrentValue("rustdoc-auto-hide-trait-implementations") !== "false") {
2300             var impl_list = document.getElementById("trait-implementations-list");
2301
2302             if (impl_list !== null) {
2303                 onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
2304                     collapser(pageId, e, collapse);
2305                 });
2306             }
2307
2308             var blanket_list = document.getElementById("blanket-implementations-list");
2309
2310             if (blanket_list !== null) {
2311                 onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
2312                     collapser(pageId, e, collapse);
2313                 });
2314             }
2315         }
2316     }
2317
2318     function insertAfter(newNode, referenceNode) {
2319         referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
2320     }
2321
2322     function createSimpleToggle(sectionIsCollapsed) {
2323         var toggle = document.createElement("a");
2324         toggle.href = "javascript:void(0)";
2325         toggle.className = "collapse-toggle";
2326         toggle.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(sectionIsCollapsed) +
2327                            "</span>]";
2328         return toggle;
2329     }
2330
2331     function createToggle(toggle, otherMessage, fontSize, extraClass, show) {
2332         var span = document.createElement("span");
2333         span.className = "toggle-label";
2334         if (show) {
2335             span.style.display = "none";
2336         }
2337         if (!otherMessage) {
2338             span.innerHTML = "&nbsp;Expand&nbsp;description";
2339         } else {
2340             span.innerHTML = otherMessage;
2341         }
2342
2343         if (fontSize) {
2344             span.style.fontSize = fontSize;
2345         }
2346
2347         var mainToggle = toggle.cloneNode(true);
2348         mainToggle.appendChild(span);
2349
2350         var wrapper = document.createElement("div");
2351         wrapper.className = "toggle-wrapper";
2352         if (!show) {
2353             addClass(wrapper, "collapsed");
2354             var inner = mainToggle.getElementsByClassName("inner");
2355             if (inner && inner.length > 0) {
2356                 inner[0].innerHTML = "+";
2357             }
2358         }
2359         if (extraClass) {
2360             addClass(wrapper, extraClass);
2361         }
2362         wrapper.appendChild(mainToggle);
2363         return wrapper;
2364     }
2365
2366     (function() {
2367         var toggles = document.getElementById(toggleAllDocsId);
2368         if (toggles) {
2369             toggles.onclick = toggleAllDocs;
2370         }
2371
2372         var toggle = createSimpleToggle(false);
2373         var hideMethodDocs = getCurrentValue("rustdoc-auto-hide-method-docs") === "true";
2374         var hideImplementors = getCurrentValue("rustdoc-auto-collapse-implementors") !== "false";
2375         var pageId = getPageId();
2376
2377         var func = function(e) {
2378             var next = e.nextElementSibling;
2379             if (!next) {
2380                 return;
2381             }
2382             if (hasClass(next, "docblock") === true ||
2383                 (hasClass(next, "stability") === true &&
2384                  hasClass(next.nextElementSibling, "docblock") === true)) {
2385                 var newToggle = toggle.cloneNode(true);
2386                 insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
2387                 if (hideMethodDocs === true && hasClass(e, "method") === true) {
2388                     collapseDocs(newToggle, "hide", pageId);
2389                 }
2390             }
2391         };
2392
2393         var funcImpl = function(e) {
2394             var next = e.nextElementSibling;
2395             if (next && hasClass(next, "docblock")) {
2396                 next = next.nextElementSibling;
2397             }
2398             if (!next) {
2399                 return;
2400             }
2401             if (hasClass(e, "impl") &&
2402                 (next.getElementsByClassName("method").length > 0 ||
2403                  next.getElementsByClassName("associatedconstant").length > 0)) {
2404                 var newToggle = toggle.cloneNode(true);
2405                 insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
2406                 // In case the option "auto-collapse implementors" is not set to false, we collapse
2407                 // all implementors.
2408                 if (hideImplementors === true && e.parentNode.id === "implementors-list") {
2409                     collapseDocs(newToggle, "hide", pageId);
2410                 }
2411             }
2412         };
2413
2414         onEachLazy(document.getElementsByClassName("method"), func);
2415         onEachLazy(document.getElementsByClassName("associatedconstant"), func);
2416         onEachLazy(document.getElementsByClassName("impl"), funcImpl);
2417         var impl_call = function() {};
2418         if (hideMethodDocs === true) {
2419             impl_call = function(e, newToggle) {
2420                 if (e.id.match(/^impl(?:-\d+)?$/) === null) {
2421                     // Automatically minimize all non-inherent impls
2422                     if (hasClass(e, "impl") === true) {
2423                         collapseDocs(newToggle, "hide", pageId);
2424                     }
2425                 }
2426             };
2427         }
2428         var newToggle = document.createElement("a");
2429         newToggle.href = "javascript:void(0)";
2430         newToggle.className = "collapse-toggle hidden-default collapsed";
2431         newToggle.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(true) +
2432                               "</span>] Show hidden undocumented items";
2433         function toggleClicked() {
2434             if (hasClass(this, "collapsed")) {
2435                 removeClass(this, "collapsed");
2436                 onEachLazy(this.parentNode.getElementsByClassName("hidden"), function(x) {
2437                     if (hasClass(x, "content") === false) {
2438                         removeClass(x, "hidden");
2439                         addClass(x, "x");
2440                     }
2441                 }, true);
2442                 this.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(false) +
2443                                  "</span>] Hide undocumented items";
2444             } else {
2445                 addClass(this, "collapsed");
2446                 onEachLazy(this.parentNode.getElementsByClassName("x"), function(x) {
2447                     if (hasClass(x, "content") === false) {
2448                         addClass(x, "hidden");
2449                         removeClass(x, "x");
2450                     }
2451                 }, true);
2452                 this.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(true) +
2453                                  "</span>] Show hidden undocumented items";
2454             }
2455         }
2456         onEachLazy(document.getElementsByClassName("impl-items"), function(e) {
2457             onEachLazy(e.getElementsByClassName("associatedconstant"), func);
2458             var hiddenElems = e.getElementsByClassName("hidden");
2459             var needToggle = false;
2460
2461             var hlength = hiddenElems.length;
2462             for (var i = 0; i < hlength; ++i) {
2463                 if (hasClass(hiddenElems[i], "content") === false &&
2464                     hasClass(hiddenElems[i], "docblock") === false) {
2465                     needToggle = true;
2466                     break;
2467                 }
2468             }
2469             if (needToggle === true) {
2470                 var inner_toggle = newToggle.cloneNode(true);
2471                 inner_toggle.onclick = toggleClicked;
2472                 e.insertBefore(inner_toggle, e.firstChild);
2473                 impl_call(e.previousSibling, inner_toggle);
2474             }
2475         });
2476
2477         var currentType = document.getElementsByClassName("type-decl")[0];
2478         var className = null;
2479         if (currentType) {
2480             currentType = currentType.getElementsByClassName("rust")[0];
2481             if (currentType) {
2482                 currentType.classList.forEach(function(item) {
2483                     if (item !== "main") {
2484                         className = item;
2485                         return true;
2486                     }
2487                 });
2488             }
2489         }
2490         var showItemDeclarations = getCurrentValue("rustdoc-auto-hide-" + className);
2491         if (showItemDeclarations === null) {
2492             if (className === "enum" || className === "macro") {
2493                 showItemDeclarations = "false";
2494             } else if (className === "struct" || className === "union" || className === "trait") {
2495                 showItemDeclarations = "true";
2496             } else {
2497                 // In case we found an unknown type, we just use the "parent" value.
2498                 showItemDeclarations = getCurrentValue("rustdoc-auto-hide-declarations");
2499             }
2500         }
2501         showItemDeclarations = showItemDeclarations === "false";
2502         function buildToggleWrapper(e) {
2503             if (hasClass(e, "autohide")) {
2504                 var wrap = e.previousElementSibling;
2505                 if (wrap && hasClass(wrap, "toggle-wrapper")) {
2506                     var inner_toggle = wrap.childNodes[0];
2507                     var extra = e.childNodes[0].tagName === "H3";
2508
2509                     e.style.display = "none";
2510                     addClass(wrap, "collapsed");
2511                     onEachLazy(inner_toggle.getElementsByClassName("inner"), function(e) {
2512                         e.innerHTML = labelForToggleButton(true);
2513                     });
2514                     onEachLazy(inner_toggle.getElementsByClassName("toggle-label"), function(e) {
2515                         e.style.display = "inline-block";
2516                         if (extra === true) {
2517                             e.innerHTML = " Show " + e.childNodes[0].innerHTML;
2518                         }
2519                     });
2520                 }
2521             }
2522             if (e.parentNode.id === "main") {
2523                 var otherMessage = "";
2524                 var fontSize;
2525                 var extraClass;
2526
2527                 if (hasClass(e, "type-decl")) {
2528                     fontSize = "20px";
2529                     otherMessage = "&nbsp;Show&nbsp;declaration";
2530                     if (showItemDeclarations === false) {
2531                         extraClass = "collapsed";
2532                     }
2533                 } else if (hasClass(e, "sub-variant")) {
2534                     otherMessage = "&nbsp;Show&nbsp;fields";
2535                 } else if (hasClass(e, "non-exhaustive")) {
2536                     otherMessage = "&nbsp;This&nbsp;";
2537                     if (hasClass(e, "non-exhaustive-struct")) {
2538                         otherMessage += "struct";
2539                     } else if (hasClass(e, "non-exhaustive-enum")) {
2540                         otherMessage += "enum";
2541                     } else if (hasClass(e, "non-exhaustive-variant")) {
2542                         otherMessage += "enum variant";
2543                     } else if (hasClass(e, "non-exhaustive-type")) {
2544                         otherMessage += "type";
2545                     }
2546                     otherMessage += "&nbsp;is&nbsp;marked&nbsp;as&nbsp;non-exhaustive";
2547                 } else if (hasClass(e.childNodes[0], "impl-items")) {
2548                     extraClass = "marg-left";
2549                 }
2550
2551                 e.parentNode.insertBefore(
2552                     createToggle(
2553                         toggle,
2554                         otherMessage,
2555                         fontSize,
2556                         extraClass,
2557                         hasClass(e, "type-decl") === false || showItemDeclarations === true),
2558                     e);
2559                 if (hasClass(e, "type-decl") === true && showItemDeclarations === true) {
2560                     collapseDocs(e.previousSibling.childNodes[0], "toggle");
2561                 }
2562                 if (hasClass(e, "non-exhaustive") === true) {
2563                     collapseDocs(e.previousSibling.childNodes[0], "toggle");
2564                 }
2565             }
2566         }
2567
2568         onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
2569         onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
2570         var pageId = getPageId();
2571
2572         autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true");
2573
2574         if (pageId !== null) {
2575             expandSection(pageId);
2576         }
2577     }());
2578
2579     function createToggleWrapper(tog) {
2580         var span = document.createElement("span");
2581         span.className = "toggle-label";
2582         span.style.display = "none";
2583         span.innerHTML = "&nbsp;Expand&nbsp;attributes";
2584         tog.appendChild(span);
2585
2586         var wrapper = document.createElement("div");
2587         wrapper.className = "toggle-wrapper toggle-attributes";
2588         wrapper.appendChild(tog);
2589         return wrapper;
2590     }
2591
2592     (function() {
2593         // To avoid checking on "rustdoc-item-attributes" value on every loop...
2594         var itemAttributesFunc = function() {};
2595         if (getCurrentValue("rustdoc-auto-hide-attributes") !== "false") {
2596             itemAttributesFunc = function(x) {
2597                 collapseDocs(x.previousSibling.childNodes[0], "toggle");
2598             };
2599         }
2600         var attributesToggle = createToggleWrapper(createSimpleToggle(false));
2601         onEachLazy(main.getElementsByClassName("attributes"), function(i_e) {
2602             var attr_tog = attributesToggle.cloneNode(true);
2603             if (hasClass(i_e, "top-attr") === true) {
2604                 addClass(attr_tog, "top-attr");
2605             }
2606             i_e.parentNode.insertBefore(attr_tog, i_e);
2607             itemAttributesFunc(i_e);
2608         });
2609     }());
2610
2611     (function() {
2612         // To avoid checking on "rustdoc-line-numbers" value on every loop...
2613         var lineNumbersFunc = function() {};
2614         if (getCurrentValue("rustdoc-line-numbers") === "true") {
2615             lineNumbersFunc = function(x) {
2616                 var count = x.textContent.split("\n").length;
2617                 var elems = [];
2618                 for (var i = 0; i < count; ++i) {
2619                     elems.push(i + 1);
2620                 }
2621                 var node = document.createElement("pre");
2622                 addClass(node, "line-number");
2623                 node.innerHTML = elems.join("\n");
2624                 x.parentNode.insertBefore(node, x);
2625             };
2626         }
2627         onEachLazy(document.getElementsByClassName("rust-example-rendered"), function(e) {
2628             if (hasClass(e, "compile_fail")) {
2629                 e.addEventListener("mouseover", function() {
2630                     this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00";
2631                 });
2632                 e.addEventListener("mouseout", function() {
2633                     this.parentElement.previousElementSibling.childNodes[0].style.color = "";
2634                 });
2635             } else if (hasClass(e, "ignore")) {
2636                 e.addEventListener("mouseover", function() {
2637                     this.parentElement.previousElementSibling.childNodes[0].style.color = "#ff9200";
2638                 });
2639                 e.addEventListener("mouseout", function() {
2640                     this.parentElement.previousElementSibling.childNodes[0].style.color = "";
2641                 });
2642             }
2643             lineNumbersFunc(e);
2644         });
2645     }());
2646
2647     onEachLazy(document.getElementsByClassName("notable-traits"), function(e) {
2648         e.onclick = function() {
2649             this.getElementsByClassName('notable-traits-tooltiptext')[0]
2650                 .classList.toggle("force-tooltip");
2651         };
2652     });
2653
2654     // In the search display, allows to switch between tabs.
2655     function printTab(nb) {
2656         if (nb === 0 || nb === 1 || nb === 2) {
2657             currentTab = nb;
2658         }
2659         var nb_copy = nb;
2660         onEachLazy(document.getElementById("titles").childNodes, function(elem) {
2661             if (nb_copy === 0) {
2662                 addClass(elem, "selected");
2663             } else {
2664                 removeClass(elem, "selected");
2665             }
2666             nb_copy -= 1;
2667         });
2668         onEachLazy(document.getElementById("results").childNodes, function(elem) {
2669             if (nb === 0) {
2670                 elem.style.display = "";
2671             } else {
2672                 elem.style.display = "none";
2673             }
2674             nb -= 1;
2675         });
2676     }
2677
2678     function putBackSearch(search_input) {
2679         var search = getSearchElement();
2680         if (search_input.value !== "" && hasClass(search, "hidden")) {
2681             showSearchResults(search);
2682             if (browserSupportsHistoryApi()) {
2683                 history.replaceState(search_input.value,
2684                                      "",
2685                                      "?search=" + encodeURIComponent(search_input.value));
2686             }
2687         }
2688     }
2689
2690     function getSearchLoadingText() {
2691         return "Loading search results...";
2692     }
2693
2694     if (search_input) {
2695         search_input.onfocus = function() {
2696             putBackSearch(this);
2697         };
2698     }
2699
2700     var params = getQueryStringParams();
2701     if (params && params.search) {
2702         var search = getSearchElement();
2703         search.innerHTML = "<h3 style=\"text-align: center;\">" + getSearchLoadingText() + "</h3>";
2704         showSearchResults(search);
2705     }
2706
2707     var sidebar_menu = document.getElementsByClassName("sidebar-menu")[0];
2708     if (sidebar_menu) {
2709         sidebar_menu.onclick = function() {
2710             var sidebar = document.getElementsByClassName("sidebar")[0];
2711             if (hasClass(sidebar, "mobile") === true) {
2712                 hideSidebar();
2713             } else {
2714                 showSidebar();
2715             }
2716         };
2717     }
2718
2719     if (main) {
2720         onEachLazy(main.getElementsByClassName("loading-content"), function(e) {
2721             e.remove();
2722         });
2723         onEachLazy(main.childNodes, function(e) {
2724             // Unhide the actual content once loading is complete. Headers get
2725             // flex treatment for their horizontal layout, divs get block treatment
2726             // for vertical layout (column-oriented flex layout for divs caused
2727             // errors in mobile browsers).
2728             if (e.tagName === "H2" || e.tagName === "H3") {
2729                 var nextTagName = e.nextElementSibling.tagName;
2730                 if (nextTagName == "H2" || nextTagName == "H3") {
2731                     e.nextElementSibling.style.display = "flex";
2732                 } else {
2733                     e.nextElementSibling.style.display = "block";
2734                 }
2735             }
2736         });
2737     }
2738
2739     function enableSearchInput() {
2740         if (search_input) {
2741             search_input.removeAttribute('disabled');
2742         }
2743     }
2744
2745     window.addSearchOptions = function(crates) {
2746         var elem = document.getElementById("crate-search");
2747
2748         if (!elem) {
2749             enableSearchInput();
2750             return;
2751         }
2752         var crates_text = [];
2753         if (Object.keys(crates).length > 1) {
2754             for (var crate in crates) {
2755                 if (hasOwnProperty(crates, crate)) {
2756                     crates_text.push(crate);
2757                 }
2758             }
2759         }
2760         crates_text.sort(function(a, b) {
2761             var lower_a = a.toLowerCase();
2762             var lower_b = b.toLowerCase();
2763
2764             if (lower_a < lower_b) {
2765                 return -1;
2766             } else if (lower_a > lower_b) {
2767                 return 1;
2768             }
2769             return 0;
2770         });
2771         var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
2772         for (var i = 0; i < crates_text.length; ++i) {
2773             var option = document.createElement("option");
2774             option.value = crates_text[i];
2775             option.innerText = crates_text[i];
2776             elem.appendChild(option);
2777             // Set the crate filter from saved storage, if the current page has the saved crate
2778             // filter.
2779             //
2780             // If not, ignore the crate filter -- we want to support filtering for crates on sites
2781             // like doc.rust-lang.org where the crates may differ from page to page while on the
2782             // same domain.
2783             if (crates_text[i] === savedCrate) {
2784                 elem.value = savedCrate;
2785             }
2786         }
2787         enableSearchInput();
2788     };
2789
2790     function buildHelperPopup() {
2791         var popup = document.createElement("aside");
2792         addClass(popup, "hidden");
2793         popup.id = "help";
2794
2795         var book_info = document.createElement("span");
2796         book_info.innerHTML = "You can find more information in \
2797             <a href=\"https://doc.rust-lang.org/rustdoc/\">the rustdoc book</a>.";
2798
2799         var container = document.createElement("div");
2800         var shortcuts = [
2801             ["?", "Show this help dialog"],
2802             ["S", "Focus the search field"],
2803             ["↑", "Move up in search results"],
2804             ["↓", "Move down in search results"],
2805             ["↹", "Switch tab"],
2806             ["&#9166;", "Go to active search result"],
2807             ["+", "Expand all sections"],
2808             ["-", "Collapse all sections"],
2809         ].map(x => "<dt><kbd>" + x[0] + "</kbd></dt><dd>" + x[1] + "</dd>").join("");
2810         var div_shortcuts = document.createElement("div");
2811         addClass(div_shortcuts, "shortcuts");
2812         div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
2813
2814         var infos = [
2815             "Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
2816              restrict the search to a given item kind.",
2817             "Accepted kinds are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
2818              <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \
2819              and <code>const</code>.",
2820             "Search functions by type signature (e.g., <code>vec -&gt; usize</code> or \
2821              <code>* -&gt; vec</code>)",
2822             "Search multiple things at once by splitting your query with comma (e.g., \
2823              <code>str,u8</code> or <code>String,struct:Vec,test</code>)",
2824             "You can look for items with an exact name by putting double quotes around \
2825              your request: <code>\"string\"</code>",
2826             "Look for items inside another one by searching for a path: <code>vec::Vec</code>",
2827         ].map(x => "<p>" + x + "</p>").join("");
2828         var div_infos = document.createElement("div");
2829         addClass(div_infos, "infos");
2830         div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;
2831
2832         container.appendChild(book_info);
2833         container.appendChild(div_shortcuts);
2834         container.appendChild(div_infos);
2835
2836         popup.appendChild(container);
2837         insertAfter(popup, getSearchElement());
2838         // So that it's only built once and then it'll do nothing when called!
2839         buildHelperPopup = function() {};
2840     }
2841
2842     onHashChange(null);
2843     window.onhashchange = onHashChange;
2844 }());
2845
2846 // This is required in firefox. Explanations: when going back in the history, firefox doesn't re-run
2847 // the JS, therefore preventing rustdoc from setting a few things required to be able to reload the
2848 // previous search results (if you navigated to a search result with the keyboard, pressed enter on
2849 // it to navigate to that result, and then came back to this page).
2850 window.onunload = function(){};