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