]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/html/static/main.js
Rollup merge of #74444 - Alexendoo:test-69414, r=nikomatsakis
[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                 if (ev.shiftKey) {
412                     displayHelp(true, ev);
413                 }
414                 break;
415             }
416         }
417     }
418
419     function findParentElement(elem, tagName) {
420         do {
421             if (elem && elem.tagName === tagName) {
422                 return elem;
423             }
424             elem = elem.parentNode;
425         } while (elem);
426         return null;
427     }
428
429     document.addEventListener("keypress", handleShortcut);
430     document.addEventListener("keydown", handleShortcut);
431
432     function resetMouseMoved(ev) {
433         mouseMovedAfterSearch = true;
434     }
435
436     document.addEventListener("mousemove", resetMouseMoved);
437
438     var handleSourceHighlight = (function() {
439         var prev_line_id = 0;
440
441         var set_fragment = function(name) {
442             var x = window.scrollX,
443                 y = window.scrollY;
444             if (browserSupportsHistoryApi()) {
445                 history.replaceState(null, null, "#" + name);
446                 highlightSourceLines();
447             } else {
448                 location.replace("#" + name);
449             }
450             // Prevent jumps when selecting one or many lines
451             window.scrollTo(x, y);
452         };
453
454         return function(ev) {
455             var cur_line_id = parseInt(ev.target.id, 10);
456             ev.preventDefault();
457
458             if (ev.shiftKey && prev_line_id) {
459                 // Swap selection if needed
460                 if (prev_line_id > cur_line_id) {
461                     var tmp = prev_line_id;
462                     prev_line_id = cur_line_id;
463                     cur_line_id = tmp;
464                 }
465
466                 set_fragment(prev_line_id + "-" + cur_line_id);
467             } else {
468                 prev_line_id = cur_line_id;
469
470                 set_fragment(cur_line_id);
471             }
472         };
473     }());
474
475     document.addEventListener("click", function(ev) {
476         if (hasClass(ev.target, "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             if (results.others.length === 1 &&
1580                 getCurrentValue("rustdoc-go-to-only-result") === "true") {
1581                 var elem = document.createElement("a");
1582                 elem.href = results.others[0].href;
1583                 elem.style.display = "none";
1584                 // For firefox, we need the element to be in the DOM so it can be clicked.
1585                 document.body.appendChild(elem);
1586                 elem.click();
1587             }
1588             var query = getQuery(search_input.value);
1589
1590             currentResults = query.id;
1591
1592             var ret_others = addTab(results.others, query);
1593             var ret_in_args = addTab(results.in_args, query, false);
1594             var ret_returned = addTab(results.returned, query, false);
1595
1596             var output = "<h1>Results for " + escape(query.query) +
1597                 (query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
1598                 "<div id=\"titles\">" +
1599                 makeTabHeader(0, "In Names", ret_others[1]) +
1600                 makeTabHeader(1, "In Parameters", ret_in_args[1]) +
1601                 makeTabHeader(2, "In Return Types", ret_returned[1]) +
1602                 "</div><div id=\"results\">" +
1603                 ret_others[0] + ret_in_args[0] + ret_returned[0] + "</div>";
1604
1605             var search = getSearchElement();
1606             search.innerHTML = output;
1607             showSearchResults(search);
1608             var tds = search.getElementsByTagName("td");
1609             var td_width = 0;
1610             if (tds.length > 0) {
1611                 td_width = tds[0].offsetWidth;
1612             }
1613             var width = search.offsetWidth - 40 - td_width;
1614             onEachLazy(search.getElementsByClassName("desc"), function(e) {
1615                 e.style.width = width + "px";
1616             });
1617             initSearchNav();
1618             var elems = document.getElementById("titles").childNodes;
1619             elems[0].onclick = function() { printTab(0); };
1620             elems[1].onclick = function() { printTab(1); };
1621             elems[2].onclick = function() { printTab(2); };
1622             printTab(currentTab);
1623         }
1624
1625         function execSearch(query, searchWords, filterCrates) {
1626             function getSmallest(arrays, positions, notDuplicates) {
1627                 var start = null;
1628
1629                 for (var it = 0; it < positions.length; ++it) {
1630                     if (arrays[it].length > positions[it] &&
1631                         (start === null || start > arrays[it][positions[it]].lev) &&
1632                         !notDuplicates[arrays[it][positions[it]].fullPath]) {
1633                         start = arrays[it][positions[it]].lev;
1634                     }
1635                 }
1636                 return start;
1637             }
1638
1639             function mergeArrays(arrays) {
1640                 var ret = [];
1641                 var positions = [];
1642                 var notDuplicates = {};
1643
1644                 for (var x = 0; x < arrays.length; ++x) {
1645                     positions.push(0);
1646                 }
1647                 while (ret.length < MAX_RESULTS) {
1648                     var smallest = getSmallest(arrays, positions, notDuplicates);
1649
1650                     if (smallest === null) {
1651                         break;
1652                     }
1653                     for (x = 0; x < arrays.length && ret.length < MAX_RESULTS; ++x) {
1654                         if (arrays[x].length > positions[x] &&
1655                                 arrays[x][positions[x]].lev === smallest &&
1656                                 !notDuplicates[arrays[x][positions[x]].fullPath]) {
1657                             ret.push(arrays[x][positions[x]]);
1658                             notDuplicates[arrays[x][positions[x]].fullPath] = true;
1659                             positions[x] += 1;
1660                         }
1661                     }
1662                 }
1663                 return ret;
1664             }
1665
1666             var queries = query.raw.split(",");
1667             var results = {
1668                 "in_args": [],
1669                 "returned": [],
1670                 "others": [],
1671             };
1672
1673             for (var i = 0; i < queries.length; ++i) {
1674                 query = queries[i].trim();
1675                 if (query.length !== 0) {
1676                     var tmp = execQuery(getQuery(query), searchWords, filterCrates);
1677
1678                     results.in_args.push(tmp.in_args);
1679                     results.returned.push(tmp.returned);
1680                     results.others.push(tmp.others);
1681                 }
1682             }
1683             if (queries.length > 1) {
1684                 return {
1685                     "in_args": mergeArrays(results.in_args),
1686                     "returned": mergeArrays(results.returned),
1687                     "others": mergeArrays(results.others),
1688                 };
1689             }
1690             return {
1691                 "in_args": results.in_args[0],
1692                 "returned": results.returned[0],
1693                 "others": results.others[0],
1694             };
1695         }
1696
1697         function getFilterCrates() {
1698             var elem = document.getElementById("crate-search");
1699
1700             if (elem && elem.value !== "All crates" && hasOwnProperty(rawSearchIndex, elem.value)) {
1701                 return elem.value;
1702             }
1703             return undefined;
1704         }
1705
1706         function search(e, forced) {
1707             var params = getQueryStringParams();
1708             var query = getQuery(search_input.value.trim());
1709
1710             if (e) {
1711                 e.preventDefault();
1712             }
1713
1714             if (query.query.length === 0) {
1715                 return;
1716             }
1717             if (forced !== true && query.id === currentResults) {
1718                 if (query.query.length > 0) {
1719                     putBackSearch(search_input);
1720                 }
1721                 return;
1722             }
1723
1724             // Update document title to maintain a meaningful browser history
1725             document.title = "Results for " + query.query + " - Rust";
1726
1727             // Because searching is incremental by character, only the most
1728             // recent search query is added to the browser history.
1729             if (browserSupportsHistoryApi()) {
1730                 if (!history.state && !params.search) {
1731                     history.pushState(query, "", "?search=" + encodeURIComponent(query.raw));
1732                 } else {
1733                     history.replaceState(query, "", "?search=" + encodeURIComponent(query.raw));
1734                 }
1735             }
1736
1737             var filterCrates = getFilterCrates();
1738             showResults(execSearch(query, index, filterCrates));
1739         }
1740
1741         function buildIndex(rawSearchIndex) {
1742             searchIndex = [];
1743             var searchWords = [];
1744             var i;
1745             var currentIndex = 0;
1746
1747             for (var crate in rawSearchIndex) {
1748                 if (!hasOwnProperty(rawSearchIndex, crate)) { continue; }
1749
1750                 var crateSize = 0;
1751
1752                 searchWords.push(crate);
1753                 searchIndex.push({
1754                     crate: crate,
1755                     ty: 1, // == ExternCrate
1756                     name: crate,
1757                     path: "",
1758                     desc: rawSearchIndex[crate].doc,
1759                     type: null,
1760                 });
1761                 currentIndex += 1;
1762
1763                 // an array of [(Number) item type,
1764                 //              (String) name,
1765                 //              (String) full path or empty string for previous path,
1766                 //              (String) description,
1767                 //              (Number | null) the parent path index to `paths`]
1768                 //              (Object | null) the type of the function (if any)
1769                 var items = rawSearchIndex[crate].i;
1770                 // an array of [(Number) item type,
1771                 //              (String) name]
1772                 var paths = rawSearchIndex[crate].p;
1773                 // a array of [(String) alias name
1774                 //             [Number] index to items]
1775                 var aliases = rawSearchIndex[crate].a;
1776
1777                 // convert `rawPaths` entries into object form
1778                 var len = paths.length;
1779                 for (i = 0; i < len; ++i) {
1780                     paths[i] = {ty: paths[i][0], name: paths[i][1]};
1781                 }
1782
1783                 // convert `items` into an object form, and construct word indices.
1784                 //
1785                 // before any analysis is performed lets gather the search terms to
1786                 // search against apart from the rest of the data.  This is a quick
1787                 // operation that is cached for the life of the page state so that
1788                 // all other search operations have access to this cached data for
1789                 // faster analysis operations
1790                 len = items.length;
1791                 var lastPath = "";
1792                 for (i = 0; i < len; ++i) {
1793                     var rawRow = items[i];
1794                     if (!rawRow[2]) {
1795                         rawRow[2] = lastPath;
1796                     }
1797                     var row = {
1798                         crate: crate,
1799                         ty: rawRow[0],
1800                         name: rawRow[1],
1801                         path: rawRow[2],
1802                         desc: rawRow[3],
1803                         parent: paths[rawRow[4]],
1804                         type: rawRow[5],
1805                     };
1806                     searchIndex.push(row);
1807                     if (typeof row.name === "string") {
1808                         var word = row.name.toLowerCase();
1809                         searchWords.push(word);
1810                     } else {
1811                         searchWords.push("");
1812                     }
1813                     lastPath = row.path;
1814                     crateSize += 1;
1815                 }
1816
1817                 if (aliases) {
1818                     ALIASES[crate] = {};
1819                     var j, local_aliases;
1820                     for (var alias_name in aliases) {
1821                         if (!aliases.hasOwnProperty(alias_name)) { continue; }
1822
1823                         if (!ALIASES[crate].hasOwnProperty(alias_name)) {
1824                             ALIASES[crate][alias_name] = [];
1825                         }
1826                         local_aliases = aliases[alias_name];
1827                         for (j = 0; j < local_aliases.length; ++j) {
1828                             ALIASES[crate][alias_name].push(local_aliases[j] + currentIndex);
1829                         }
1830                     }
1831                 }
1832                 currentIndex += crateSize;
1833             }
1834             return searchWords;
1835         }
1836
1837         function startSearch() {
1838             var callback = function() {
1839                 clearInputTimeout();
1840                 if (search_input.value.length === 0) {
1841                     if (browserSupportsHistoryApi()) {
1842                         history.replaceState("", window.currentCrate + " - Rust", "?search=");
1843                     }
1844                     hideSearchResults();
1845                 } else {
1846                     searchTimeout = setTimeout(search, 500);
1847                 }
1848             };
1849             search_input.onkeyup = callback;
1850             search_input.oninput = callback;
1851             document.getElementsByClassName("search-form")[0].onsubmit = function(e) {
1852                 e.preventDefault();
1853                 clearInputTimeout();
1854                 search();
1855             };
1856             search_input.onchange = function(e) {
1857                 if (e.target !== document.activeElement) {
1858                     // To prevent doing anything when it's from a blur event.
1859                     return;
1860                 }
1861                 // Do NOT e.preventDefault() here. It will prevent pasting.
1862                 clearInputTimeout();
1863                 // zero-timeout necessary here because at the time of event handler execution the
1864                 // pasted content is not in the input field yet. Shouldn’t make any difference for
1865                 // change, though.
1866                 setTimeout(search, 0);
1867             };
1868             search_input.onpaste = search_input.onchange;
1869
1870             var selectCrate = document.getElementById("crate-search");
1871             if (selectCrate) {
1872                 selectCrate.onchange = function() {
1873                     updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value);
1874                     search(undefined, true);
1875                 };
1876             }
1877
1878             // Push and pop states are used to add search results to the browser
1879             // history.
1880             if (browserSupportsHistoryApi()) {
1881                 // Store the previous <title> so we can revert back to it later.
1882                 var previousTitle = document.title;
1883
1884                 window.addEventListener("popstate", function(e) {
1885                     var params = getQueryStringParams();
1886                     // Revert to the previous title manually since the History
1887                     // API ignores the title parameter.
1888                     document.title = previousTitle;
1889                     // When browsing forward to search results the previous
1890                     // search will be repeated, so the currentResults are
1891                     // cleared to ensure the search is successful.
1892                     currentResults = null;
1893                     // Synchronize search bar with query string state and
1894                     // perform the search. This will empty the bar if there's
1895                     // nothing there, which lets you really go back to a
1896                     // previous state with nothing in the bar.
1897                     if (params.search && params.search.length > 0) {
1898                         search_input.value = params.search;
1899                         // Some browsers fire "onpopstate" for every page load
1900                         // (Chrome), while others fire the event only when actually
1901                         // popping a state (Firefox), which is why search() is
1902                         // called both here and at the end of the startSearch()
1903                         // function.
1904                         search(e);
1905                     } else {
1906                         search_input.value = "";
1907                         // When browsing back from search results the main page
1908                         // visibility must be reset.
1909                         hideSearchResults();
1910                     }
1911                 });
1912             }
1913             search();
1914         }
1915
1916         index = buildIndex(rawSearchIndex);
1917         startSearch();
1918
1919         // Draw a convenient sidebar of known crates if we have a listing
1920         if (rootPath === "../" || rootPath === "./") {
1921             var sidebar = document.getElementsByClassName("sidebar-elems")[0];
1922             if (sidebar) {
1923                 var div = document.createElement("div");
1924                 div.className = "block crate";
1925                 div.innerHTML = "<h3>Crates</h3>";
1926                 var ul = document.createElement("ul");
1927                 div.appendChild(ul);
1928
1929                 var crates = [];
1930                 for (var crate in rawSearchIndex) {
1931                     if (!hasOwnProperty(rawSearchIndex, crate)) {
1932                         continue;
1933                     }
1934                     crates.push(crate);
1935                 }
1936                 crates.sort();
1937                 for (var i = 0; i < crates.length; ++i) {
1938                     var klass = "crate";
1939                     if (rootPath !== "./" && crates[i] === window.currentCrate) {
1940                         klass += " current";
1941                     }
1942                     var link = document.createElement("a");
1943                     link.href = rootPath + crates[i] + "/index.html";
1944                     link.title = rawSearchIndex[crates[i]].doc;
1945                     link.className = klass;
1946                     link.textContent = crates[i];
1947
1948                     var li = document.createElement("li");
1949                     li.appendChild(link);
1950                     ul.appendChild(li);
1951                 }
1952                 sidebar.appendChild(div);
1953             }
1954         }
1955     };
1956
1957
1958     // delayed sidebar rendering.
1959     window.initSidebarItems = function(items) {
1960         var sidebar = document.getElementsByClassName("sidebar-elems")[0];
1961         var current = window.sidebarCurrent;
1962
1963         function block(shortty, longty) {
1964             var filtered = items[shortty];
1965             if (!filtered) {
1966                 return;
1967             }
1968
1969             var div = document.createElement("div");
1970             div.className = "block " + shortty;
1971             var h3 = document.createElement("h3");
1972             h3.textContent = longty;
1973             div.appendChild(h3);
1974             var ul = document.createElement("ul");
1975
1976             var length = filtered.length;
1977             for (var i = 0; i < length; ++i) {
1978                 var item = filtered[i];
1979                 var name = item[0];
1980                 var desc = item[1]; // can be null
1981
1982                 var klass = shortty;
1983                 if (name === current.name && shortty === current.ty) {
1984                     klass += " current";
1985                 }
1986                 var path;
1987                 if (shortty === "mod") {
1988                     path = name + "/index.html";
1989                 } else {
1990                     path = shortty + "." + name + ".html";
1991                 }
1992                 var link = document.createElement("a");
1993                 link.href = current.relpath + path;
1994                 link.title = desc;
1995                 link.className = klass;
1996                 link.textContent = name;
1997                 var li = document.createElement("li");
1998                 li.appendChild(link);
1999                 ul.appendChild(li);
2000             }
2001             div.appendChild(ul);
2002             if (sidebar) {
2003                 sidebar.appendChild(div);
2004             }
2005         }
2006
2007         block("primitive", "Primitive Types");
2008         block("mod", "Modules");
2009         block("macro", "Macros");
2010         block("struct", "Structs");
2011         block("enum", "Enums");
2012         block("union", "Unions");
2013         block("constant", "Constants");
2014         block("static", "Statics");
2015         block("trait", "Traits");
2016         block("fn", "Functions");
2017         block("type", "Type Definitions");
2018         block("foreigntype", "Foreign Types");
2019         block("keyword", "Keywords");
2020         block("traitalias", "Trait Aliases");
2021     };
2022
2023     window.register_implementors = function(imp) {
2024         var implementors = document.getElementById("implementors-list");
2025         var synthetic_implementors = document.getElementById("synthetic-implementors-list");
2026
2027         if (synthetic_implementors) {
2028             // This `inlined_types` variable is used to avoid having the same implementation
2029             // showing up twice. For example "String" in the "Sync" doc page.
2030             //
2031             // By the way, this is only used by and useful for traits implemented automatically
2032             // (like "Send" and "Sync").
2033             var inlined_types = new Set();
2034             onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) {
2035                 var aliases = el.getAttribute("aliases");
2036                 if (!aliases) {
2037                     return;
2038                 }
2039                 aliases.split(",").forEach(function(alias) {
2040                     inlined_types.add(alias);
2041                 });
2042             });
2043         }
2044
2045         var libs = Object.getOwnPropertyNames(imp);
2046         var llength = libs.length;
2047         for (var i = 0; i < llength; ++i) {
2048             if (libs[i] === currentCrate) { continue; }
2049             var structs = imp[libs[i]];
2050
2051             var slength = structs.length;
2052             struct_loop:
2053             for (var j = 0; j < slength; ++j) {
2054                 var struct = structs[j];
2055
2056                 var list = struct.synthetic ? synthetic_implementors : implementors;
2057
2058                 if (struct.synthetic) {
2059                     var stlength = struct.types.length;
2060                     for (var k = 0; k < stlength; k++) {
2061                         if (inlined_types.has(struct.types[k])) {
2062                             continue struct_loop;
2063                         }
2064                         inlined_types.add(struct.types[k]);
2065                     }
2066                 }
2067
2068                 var code = document.createElement("code");
2069                 code.innerHTML = struct.text;
2070
2071                 var x = code.getElementsByTagName("a");
2072                 var xlength = x.length;
2073                 for (var it = 0; it < xlength; it++) {
2074                     var href = x[it].getAttribute("href");
2075                     if (href && href.indexOf("http") !== 0) {
2076                         x[it].setAttribute("href", rootPath + href);
2077                     }
2078                 }
2079                 var display = document.createElement("h3");
2080                 addClass(display, "impl");
2081                 display.innerHTML = "<span class=\"in-band\"><table class=\"table-display\">" +
2082                     "<tbody><tr><td><code>" + code.outerHTML + "</code></td><td></td></tr>" +
2083                     "</tbody></table></span>";
2084                 list.appendChild(display);
2085             }
2086         }
2087     };
2088     if (window.pending_implementors) {
2089         window.register_implementors(window.pending_implementors);
2090     }
2091
2092     function labelForToggleButton(sectionIsCollapsed) {
2093         if (sectionIsCollapsed) {
2094             // button will expand the section
2095             return "+";
2096         }
2097         // button will collapse the section
2098         // note that this text is also set in the HTML template in render.rs
2099         return "\u2212"; // "\u2212" is "−" minus sign
2100     }
2101
2102     function onEveryMatchingChild(elem, className, func) {
2103         if (elem && className && func) {
2104             var length = elem.childNodes.length;
2105             var nodes = elem.childNodes;
2106             for (var i = 0; i < length; ++i) {
2107                 if (hasClass(nodes[i], className)) {
2108                     func(nodes[i]);
2109                 } else {
2110                     onEveryMatchingChild(nodes[i], className, func);
2111                 }
2112             }
2113         }
2114     }
2115
2116     function toggleAllDocs(pageId, fromAutoCollapse) {
2117         var innerToggle = document.getElementById("toggle-all-docs");
2118         if (!innerToggle) {
2119             return;
2120         }
2121         if (hasClass(innerToggle, "will-expand")) {
2122             updateLocalStorage("rustdoc-collapse", "false");
2123             removeClass(innerToggle, "will-expand");
2124             onEveryMatchingChild(innerToggle, "inner", function(e) {
2125                 e.innerHTML = labelForToggleButton(false);
2126             });
2127             innerToggle.title = "collapse all docs";
2128             if (fromAutoCollapse !== true) {
2129                 onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
2130                     collapseDocs(e, "show");
2131                 });
2132             }
2133         } else {
2134             updateLocalStorage("rustdoc-collapse", "true");
2135             addClass(innerToggle, "will-expand");
2136             onEveryMatchingChild(innerToggle, "inner", function(e) {
2137                 var parent = e.parentNode;
2138                 var superParent = null;
2139
2140                 if (parent) {
2141                     superParent = parent.parentNode;
2142                 }
2143                 if (!parent || !superParent || superParent.id !== "main" ||
2144                     hasClass(parent, "impl") === false) {
2145                     e.innerHTML = labelForToggleButton(true);
2146                 }
2147             });
2148             innerToggle.title = "expand all docs";
2149             if (fromAutoCollapse !== true) {
2150                 onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
2151                     var parent = e.parentNode;
2152                     var superParent = null;
2153
2154                     if (parent) {
2155                         superParent = parent.parentNode;
2156                     }
2157                     if (!parent || !superParent || superParent.id !== "main" ||
2158                         hasClass(parent, "impl") === false) {
2159                         collapseDocs(e, "hide", pageId);
2160                     }
2161                 });
2162             }
2163         }
2164     }
2165
2166     function collapseDocs(toggle, mode, pageId) {
2167         if (!toggle || !toggle.parentNode) {
2168             return;
2169         }
2170
2171         function adjustToggle(arg) {
2172             return function(e) {
2173                 if (hasClass(e, "toggle-label")) {
2174                     if (arg) {
2175                         e.style.display = "inline-block";
2176                     } else {
2177                         e.style.display = "none";
2178                     }
2179                 }
2180                 if (hasClass(e, "inner")) {
2181                     e.innerHTML = labelForToggleButton(arg);
2182                 }
2183             };
2184         }
2185
2186         function implHider(addOrRemove, fullHide) {
2187             return function(n) {
2188                 var is_method = hasClass(n, "method") || fullHide;
2189                 if (is_method || hasClass(n, "type")) {
2190                     if (is_method === true) {
2191                         if (addOrRemove) {
2192                             addClass(n, "hidden-by-impl-hider");
2193                         } else {
2194                             removeClass(n, "hidden-by-impl-hider");
2195                         }
2196                     }
2197                     var ns = n.nextElementSibling;
2198                     while (ns && (hasClass(ns, "docblock") || hasClass(ns, "stability"))) {
2199                         if (addOrRemove) {
2200                             addClass(ns, "hidden-by-impl-hider");
2201                         } else {
2202                             removeClass(ns, "hidden-by-impl-hider");
2203                         }
2204                         ns = ns.nextElementSibling;
2205                     }
2206                 }
2207             };
2208         }
2209
2210         var relatedDoc;
2211         var action = mode;
2212         if (hasClass(toggle.parentNode, "impl") === false) {
2213             relatedDoc = toggle.parentNode.nextElementSibling;
2214             if (hasClass(relatedDoc, "stability")) {
2215                 relatedDoc = relatedDoc.nextElementSibling;
2216             }
2217             if (hasClass(relatedDoc, "docblock") || hasClass(relatedDoc, "sub-variant")) {
2218                 if (mode === "toggle") {
2219                     if (hasClass(relatedDoc, "hidden-by-usual-hider")) {
2220                         action = "show";
2221                     } else {
2222                         action = "hide";
2223                     }
2224                 }
2225                 if (action === "hide") {
2226                     addClass(relatedDoc, "hidden-by-usual-hider");
2227                     onEachLazy(toggle.childNodes, adjustToggle(true));
2228                     addClass(toggle.parentNode, "collapsed");
2229                 } else if (action === "show") {
2230                     removeClass(relatedDoc, "hidden-by-usual-hider");
2231                     removeClass(toggle.parentNode, "collapsed");
2232                     onEachLazy(toggle.childNodes, adjustToggle(false));
2233                 }
2234             }
2235         } else {
2236             // we are collapsing the impl block(s).
2237
2238             var parentElem = toggle.parentNode;
2239             relatedDoc = parentElem;
2240             var docblock = relatedDoc.nextElementSibling;
2241
2242             while (hasClass(relatedDoc, "impl-items") === false) {
2243                 relatedDoc = relatedDoc.nextElementSibling;
2244             }
2245
2246             if (!relatedDoc && hasClass(docblock, "docblock") === false) {
2247                 return;
2248             }
2249
2250             // Hide all functions, but not associated types/consts.
2251
2252             if (mode === "toggle") {
2253                 if (hasClass(relatedDoc, "fns-now-collapsed") ||
2254                     hasClass(docblock, "hidden-by-impl-hider")) {
2255                     action = "show";
2256                 } else {
2257                     action = "hide";
2258                 }
2259             }
2260
2261             var dontApplyBlockRule = toggle.parentNode.parentNode.id !== "main";
2262             if (action === "show") {
2263                 removeClass(relatedDoc, "fns-now-collapsed");
2264                 removeClass(docblock, "hidden-by-usual-hider");
2265                 onEachLazy(toggle.childNodes, adjustToggle(false, dontApplyBlockRule));
2266                 onEachLazy(relatedDoc.childNodes, implHider(false, dontApplyBlockRule));
2267             } else if (action === "hide") {
2268                 addClass(relatedDoc, "fns-now-collapsed");
2269                 addClass(docblock, "hidden-by-usual-hider");
2270                 onEachLazy(toggle.childNodes, adjustToggle(true, dontApplyBlockRule));
2271                 onEachLazy(relatedDoc.childNodes, implHider(true, dontApplyBlockRule));
2272             }
2273         }
2274     }
2275
2276     function collapser(pageId, e, collapse) {
2277         // inherent impl ids are like "impl" or impl-<number>'.
2278         // they will never be hidden by default.
2279         var n = e.parentElement;
2280         if (n.id.match(/^impl(?:-\d+)?$/) === null) {
2281             // Automatically minimize all non-inherent impls
2282             if (collapse || hasClass(n, "impl")) {
2283                 collapseDocs(e, "hide", pageId);
2284             }
2285         }
2286     }
2287
2288     function autoCollapse(pageId, collapse) {
2289         if (collapse) {
2290             toggleAllDocs(pageId, true);
2291         } else if (getCurrentValue("rustdoc-auto-hide-trait-implementations") !== "false") {
2292             var impl_list = document.getElementById("trait-implementations-list");
2293
2294             if (impl_list !== null) {
2295                 onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
2296                     collapser(pageId, e, collapse);
2297                 });
2298             }
2299
2300             var blanket_list = document.getElementById("blanket-implementations-list");
2301
2302             if (blanket_list !== null) {
2303                 onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
2304                     collapser(pageId, e, collapse);
2305                 });
2306             }
2307         }
2308     }
2309
2310     var toggles = document.getElementById("toggle-all-docs");
2311     if (toggles) {
2312         toggles.onclick = toggleAllDocs;
2313     }
2314
2315     function insertAfter(newNode, referenceNode) {
2316         referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
2317     }
2318
2319     function createSimpleToggle(sectionIsCollapsed) {
2320         var toggle = document.createElement("a");
2321         toggle.href = "javascript:void(0)";
2322         toggle.className = "collapse-toggle";
2323         toggle.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(sectionIsCollapsed) +
2324                            "</span>]";
2325         return toggle;
2326     }
2327
2328     function createToggle(toggle, otherMessage, fontSize, extraClass, show) {
2329         var span = document.createElement("span");
2330         span.className = "toggle-label";
2331         if (show) {
2332             span.style.display = "none";
2333         }
2334         if (!otherMessage) {
2335             span.innerHTML = "&nbsp;Expand&nbsp;description";
2336         } else {
2337             span.innerHTML = otherMessage;
2338         }
2339
2340         if (fontSize) {
2341             span.style.fontSize = fontSize;
2342         }
2343
2344         var mainToggle = toggle.cloneNode(true);
2345         mainToggle.appendChild(span);
2346
2347         var wrapper = document.createElement("div");
2348         wrapper.className = "toggle-wrapper";
2349         if (!show) {
2350             addClass(wrapper, "collapsed");
2351             var inner = mainToggle.getElementsByClassName("inner");
2352             if (inner && inner.length > 0) {
2353                 inner[0].innerHTML = "+";
2354             }
2355         }
2356         if (extraClass) {
2357             addClass(wrapper, extraClass);
2358         }
2359         wrapper.appendChild(mainToggle);
2360         return wrapper;
2361     }
2362
2363     (function() {
2364         var toggle = createSimpleToggle(false);
2365         var hideMethodDocs = getCurrentValue("rustdoc-auto-hide-method-docs") === "true";
2366         var hideImplementors = getCurrentValue("rustdoc-auto-collapse-implementors") !== "false";
2367         var pageId = getPageId();
2368
2369         var func = function(e) {
2370             var next = e.nextElementSibling;
2371             if (!next) {
2372                 return;
2373             }
2374             if (hasClass(next, "docblock") === true ||
2375                 (hasClass(next, "stability") === true &&
2376                  hasClass(next.nextElementSibling, "docblock") === true)) {
2377                 var newToggle = toggle.cloneNode(true);
2378                 insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
2379                 if (hideMethodDocs === true && hasClass(e, "method") === true) {
2380                     collapseDocs(newToggle, "hide", pageId);
2381                 }
2382             }
2383         };
2384
2385         var funcImpl = function(e) {
2386             var next = e.nextElementSibling;
2387             if (next && hasClass(next, "docblock")) {
2388                 next = next.nextElementSibling;
2389             }
2390             if (!next) {
2391                 return;
2392             }
2393             if (hasClass(e, "impl") &&
2394                 (next.getElementsByClassName("method").length > 0 ||
2395                  next.getElementsByClassName("associatedconstant").length > 0)) {
2396                 var newToggle = toggle.cloneNode(true);
2397                 insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
2398                 // In case the option "auto-collapse implementors" is not set to false, we collapse
2399                 // all implementors.
2400                 if (hideImplementors === true && e.parentNode.id === "implementors-list") {
2401                     collapseDocs(newToggle, "hide", pageId);
2402                 }
2403             }
2404         };
2405
2406         onEachLazy(document.getElementsByClassName("method"), func);
2407         onEachLazy(document.getElementsByClassName("associatedconstant"), func);
2408         onEachLazy(document.getElementsByClassName("impl"), funcImpl);
2409         var impl_call = function() {};
2410         if (hideMethodDocs === true) {
2411             impl_call = function(e, newToggle) {
2412                 if (e.id.match(/^impl(?:-\d+)?$/) === null) {
2413                     // Automatically minimize all non-inherent impls
2414                     if (hasClass(e, "impl") === true) {
2415                         collapseDocs(newToggle, "hide", pageId);
2416                     }
2417                 }
2418             };
2419         }
2420         var newToggle = document.createElement("a");
2421         newToggle.href = "javascript:void(0)";
2422         newToggle.className = "collapse-toggle hidden-default collapsed";
2423         newToggle.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(true) +
2424                               "</span>] Show hidden undocumented items";
2425         function toggleClicked() {
2426             if (hasClass(this, "collapsed")) {
2427                 removeClass(this, "collapsed");
2428                 onEachLazy(this.parentNode.getElementsByClassName("hidden"), function(x) {
2429                     if (hasClass(x, "content") === false) {
2430                         removeClass(x, "hidden");
2431                         addClass(x, "x");
2432                     }
2433                 }, true);
2434                 this.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(false) +
2435                                  "</span>] Hide undocumented items";
2436             } else {
2437                 addClass(this, "collapsed");
2438                 onEachLazy(this.parentNode.getElementsByClassName("x"), function(x) {
2439                     if (hasClass(x, "content") === false) {
2440                         addClass(x, "hidden");
2441                         removeClass(x, "x");
2442                     }
2443                 }, true);
2444                 this.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(true) +
2445                                  "</span>] Show hidden undocumented items";
2446             }
2447         }
2448         onEachLazy(document.getElementsByClassName("impl-items"), function(e) {
2449             onEachLazy(e.getElementsByClassName("associatedconstant"), func);
2450             var hiddenElems = e.getElementsByClassName("hidden");
2451             var needToggle = false;
2452
2453             var hlength = hiddenElems.length;
2454             for (var i = 0; i < hlength; ++i) {
2455                 if (hasClass(hiddenElems[i], "content") === false &&
2456                     hasClass(hiddenElems[i], "docblock") === false) {
2457                     needToggle = true;
2458                     break;
2459                 }
2460             }
2461             if (needToggle === true) {
2462                 var inner_toggle = newToggle.cloneNode(true);
2463                 inner_toggle.onclick = toggleClicked;
2464                 e.insertBefore(inner_toggle, e.firstChild);
2465                 impl_call(e.previousSibling, inner_toggle);
2466             }
2467         });
2468
2469         var currentType = document.getElementsByClassName("type-decl")[0];
2470         var className = null;
2471         if (currentType) {
2472             currentType = currentType.getElementsByClassName("rust")[0];
2473             if (currentType) {
2474                 currentType.classList.forEach(function(item) {
2475                     if (item !== "main") {
2476                         className = item;
2477                         return true;
2478                     }
2479                 });
2480             }
2481         }
2482         var showItemDeclarations = getCurrentValue("rustdoc-auto-hide-" + className);
2483         if (showItemDeclarations === null) {
2484             if (className === "enum" || className === "macro") {
2485                 showItemDeclarations = "false";
2486             } else if (className === "struct" || className === "union" || className === "trait") {
2487                 showItemDeclarations = "true";
2488             } else {
2489                 // In case we found an unknown type, we just use the "parent" value.
2490                 showItemDeclarations = getCurrentValue("rustdoc-auto-hide-declarations");
2491             }
2492         }
2493         showItemDeclarations = showItemDeclarations === "false";
2494         function buildToggleWrapper(e) {
2495             if (hasClass(e, "autohide")) {
2496                 var wrap = e.previousElementSibling;
2497                 if (wrap && hasClass(wrap, "toggle-wrapper")) {
2498                     var inner_toggle = wrap.childNodes[0];
2499                     var extra = e.childNodes[0].tagName === "H3";
2500
2501                     e.style.display = "none";
2502                     addClass(wrap, "collapsed");
2503                     onEachLazy(inner_toggle.getElementsByClassName("inner"), function(e) {
2504                         e.innerHTML = labelForToggleButton(true);
2505                     });
2506                     onEachLazy(inner_toggle.getElementsByClassName("toggle-label"), function(e) {
2507                         e.style.display = "inline-block";
2508                         if (extra === true) {
2509                             e.innerHTML = " Show " + e.childNodes[0].innerHTML;
2510                         }
2511                     });
2512                 }
2513             }
2514             if (e.parentNode.id === "main") {
2515                 var otherMessage = "";
2516                 var fontSize;
2517                 var extraClass;
2518
2519                 if (hasClass(e, "type-decl")) {
2520                     fontSize = "20px";
2521                     otherMessage = "&nbsp;Show&nbsp;declaration";
2522                     if (showItemDeclarations === false) {
2523                         extraClass = "collapsed";
2524                     }
2525                 } else if (hasClass(e, "sub-variant")) {
2526                     otherMessage = "&nbsp;Show&nbsp;fields";
2527                 } else if (hasClass(e, "non-exhaustive")) {
2528                     otherMessage = "&nbsp;This&nbsp;";
2529                     if (hasClass(e, "non-exhaustive-struct")) {
2530                         otherMessage += "struct";
2531                     } else if (hasClass(e, "non-exhaustive-enum")) {
2532                         otherMessage += "enum";
2533                     } else if (hasClass(e, "non-exhaustive-variant")) {
2534                         otherMessage += "enum variant";
2535                     } else if (hasClass(e, "non-exhaustive-type")) {
2536                         otherMessage += "type";
2537                     }
2538                     otherMessage += "&nbsp;is&nbsp;marked&nbsp;as&nbsp;non-exhaustive";
2539                 } else if (hasClass(e.childNodes[0], "impl-items")) {
2540                     extraClass = "marg-left";
2541                 }
2542
2543                 e.parentNode.insertBefore(
2544                     createToggle(
2545                         toggle,
2546                         otherMessage,
2547                         fontSize,
2548                         extraClass,
2549                         hasClass(e, "type-decl") === false || showItemDeclarations === true),
2550                     e);
2551                 if (hasClass(e, "type-decl") === true && showItemDeclarations === true) {
2552                     collapseDocs(e.previousSibling.childNodes[0], "toggle");
2553                 }
2554                 if (hasClass(e, "non-exhaustive") === true) {
2555                     collapseDocs(e.previousSibling.childNodes[0], "toggle");
2556                 }
2557             }
2558         }
2559
2560         onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
2561         onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
2562         var pageId = getPageId();
2563
2564         autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true");
2565
2566         if (pageId !== null) {
2567             expandSection(pageId);
2568         }
2569     }());
2570
2571     function createToggleWrapper(tog) {
2572         var span = document.createElement("span");
2573         span.className = "toggle-label";
2574         span.style.display = "none";
2575         span.innerHTML = "&nbsp;Expand&nbsp;attributes";
2576         tog.appendChild(span);
2577
2578         var wrapper = document.createElement("div");
2579         wrapper.className = "toggle-wrapper toggle-attributes";
2580         wrapper.appendChild(tog);
2581         return wrapper;
2582     }
2583
2584     (function() {
2585         // To avoid checking on "rustdoc-item-attributes" value on every loop...
2586         var itemAttributesFunc = function() {};
2587         if (getCurrentValue("rustdoc-auto-hide-attributes") !== "false") {
2588             itemAttributesFunc = function(x) {
2589                 collapseDocs(x.previousSibling.childNodes[0], "toggle");
2590             };
2591         }
2592         var attributesToggle = createToggleWrapper(createSimpleToggle(false));
2593         onEachLazy(main.getElementsByClassName("attributes"), function(i_e) {
2594             var attr_tog = attributesToggle.cloneNode(true);
2595             if (hasClass(i_e, "top-attr") === true) {
2596                 addClass(attr_tog, "top-attr");
2597             }
2598             i_e.parentNode.insertBefore(attr_tog, i_e);
2599             itemAttributesFunc(i_e);
2600         });
2601     }());
2602
2603     (function() {
2604         // To avoid checking on "rustdoc-line-numbers" value on every loop...
2605         var lineNumbersFunc = function() {};
2606         if (getCurrentValue("rustdoc-line-numbers") === "true") {
2607             lineNumbersFunc = function(x) {
2608                 var count = x.textContent.split("\n").length;
2609                 var elems = [];
2610                 for (var i = 0; i < count; ++i) {
2611                     elems.push(i + 1);
2612                 }
2613                 var node = document.createElement("pre");
2614                 addClass(node, "line-number");
2615                 node.innerHTML = elems.join("\n");
2616                 x.parentNode.insertBefore(node, x);
2617             };
2618         }
2619         onEachLazy(document.getElementsByClassName("rust-example-rendered"), function(e) {
2620             if (hasClass(e, "compile_fail")) {
2621                 e.addEventListener("mouseover", function() {
2622                     this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00";
2623                 });
2624                 e.addEventListener("mouseout", function() {
2625                     this.parentElement.previousElementSibling.childNodes[0].style.color = "";
2626                 });
2627             } else if (hasClass(e, "ignore")) {
2628                 e.addEventListener("mouseover", function() {
2629                     this.parentElement.previousElementSibling.childNodes[0].style.color = "#ff9200";
2630                 });
2631                 e.addEventListener("mouseout", function() {
2632                     this.parentElement.previousElementSibling.childNodes[0].style.color = "";
2633                 });
2634             }
2635             lineNumbersFunc(e);
2636         });
2637     }());
2638
2639     onEachLazy(document.getElementsByClassName("important-traits"), function(e) {
2640         e.onclick = function() {
2641             this.getElementsByClassName('important-traits-tooltiptext')[0]
2642                 .classList.toggle("force-tooltip");
2643         };
2644     });
2645
2646     // In the search display, allows to switch between tabs.
2647     function printTab(nb) {
2648         if (nb === 0 || nb === 1 || nb === 2) {
2649             currentTab = nb;
2650         }
2651         var nb_copy = nb;
2652         onEachLazy(document.getElementById("titles").childNodes, function(elem) {
2653             if (nb_copy === 0) {
2654                 addClass(elem, "selected");
2655             } else {
2656                 removeClass(elem, "selected");
2657             }
2658             nb_copy -= 1;
2659         });
2660         onEachLazy(document.getElementById("results").childNodes, function(elem) {
2661             if (nb === 0) {
2662                 elem.style.display = "";
2663             } else {
2664                 elem.style.display = "none";
2665             }
2666             nb -= 1;
2667         });
2668     }
2669
2670     function putBackSearch(search_input) {
2671         var search = getSearchElement();
2672         if (search_input.value !== "" && hasClass(search, "hidden")) {
2673             showSearchResults(search);
2674             if (browserSupportsHistoryApi()) {
2675                 history.replaceState(search_input.value,
2676                                      "",
2677                                      "?search=" + encodeURIComponent(search_input.value));
2678             }
2679         }
2680     }
2681
2682     if (search_input) {
2683         search_input.onfocus = function() {
2684             putBackSearch(this);
2685         };
2686     }
2687
2688     var params = getQueryStringParams();
2689     if (params && params.search) {
2690         var search = getSearchElement();
2691         search.innerHTML = "<h3 style=\"text-align: center;\">Loading search results...</h3>";
2692         showSearchResults(search);
2693     }
2694
2695     var sidebar_menu = document.getElementsByClassName("sidebar-menu")[0];
2696     if (sidebar_menu) {
2697         sidebar_menu.onclick = function() {
2698             var sidebar = document.getElementsByClassName("sidebar")[0];
2699             if (hasClass(sidebar, "mobile") === true) {
2700                 hideSidebar();
2701             } else {
2702                 showSidebar();
2703             }
2704         };
2705     }
2706
2707     window.onresize = function() {
2708         hideSidebar();
2709     };
2710
2711     if (main) {
2712         onEachLazy(main.getElementsByClassName("loading-content"), function(e) {
2713             e.remove();
2714         });
2715         onEachLazy(main.childNodes, function(e) {
2716             // Unhide the actual content once loading is complete. Headers get
2717             // flex treatment for their horizontal layout, divs get block treatment
2718             // for vertical layout (column-oriented flex layout for divs caused
2719             // errors in mobile browsers).
2720             if (e.tagName === "H2" || e.tagName === "H3") {
2721                 var nextTagName = e.nextElementSibling.tagName;
2722                 if (nextTagName == "H2" || nextTagName == "H3") {
2723                     e.nextElementSibling.style.display = "flex";
2724                 } else {
2725                     e.nextElementSibling.style.display = "block";
2726                 }
2727             }
2728         });
2729     }
2730
2731     window.addSearchOptions = function(crates) {
2732         var elem = document.getElementById("crate-search");
2733
2734         if (!elem) {
2735             return;
2736         }
2737         var crates_text = [];
2738         if (Object.keys(crates).length > 1) {
2739             for (var crate in crates) {
2740                 if (hasOwnProperty(crates, crate)) {
2741                     crates_text.push(crate);
2742                 }
2743             }
2744         }
2745         crates_text.sort(function(a, b) {
2746             var lower_a = a.toLowerCase();
2747             var lower_b = b.toLowerCase();
2748
2749             if (lower_a < lower_b) {
2750                 return -1;
2751             } else if (lower_a > lower_b) {
2752                 return 1;
2753             }
2754             return 0;
2755         });
2756         var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
2757         for (var i = 0; i < crates_text.length; ++i) {
2758             var option = document.createElement("option");
2759             option.value = crates_text[i];
2760             option.innerText = crates_text[i];
2761             elem.appendChild(option);
2762             // Set the crate filter from saved storage, if the current page has the saved crate
2763             // filter.
2764             //
2765             // If not, ignore the crate filter -- we want to support filtering for crates on sites
2766             // like doc.rust-lang.org where the crates may differ from page to page while on the
2767             // same domain.
2768             if (crates_text[i] === savedCrate) {
2769                 elem.value = savedCrate;
2770             }
2771         }
2772
2773         if (search_input) {
2774             search_input.removeAttribute('disabled');
2775         }
2776     };
2777
2778     function buildHelperPopup() {
2779         var popup = document.createElement("aside");
2780         addClass(popup, "hidden");
2781         popup.id = "help";
2782
2783         var container = document.createElement("div");
2784         var shortcuts = [
2785             ["?", "Show this help dialog"],
2786             ["S", "Focus the search field"],
2787             ["↑", "Move up in search results"],
2788             ["↓", "Move down in search results"],
2789             ["↹", "Switch tab"],
2790             ["&#9166;", "Go to active search result"],
2791             ["+", "Expand all sections"],
2792             ["-", "Collapse all sections"],
2793         ].map(x => "<dt><kbd>" + x[0] + "</kbd></dt><dd>" + x[1] + "</dd>").join("");
2794         var div_shortcuts = document.createElement("div");
2795         addClass(div_shortcuts, "shortcuts");
2796         div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
2797
2798         var infos = [
2799             "Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
2800              restrict the search to a given type.",
2801             "Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
2802              <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \
2803              and <code>const</code>.",
2804             "Search functions by type signature (e.g., <code>vec -&gt; usize</code> or \
2805              <code>* -&gt; vec</code>)",
2806             "Search multiple things at once by splitting your query with comma (e.g., \
2807              <code>str,u8</code> or <code>String,struct:Vec,test</code>)",
2808             "You can look for items with an exact name by putting double quotes around \
2809              your request: <code>\"string\"</code>",
2810             "Look for items inside another one by searching for a path: <code>vec::Vec</code>",
2811         ].map(x => "<p>" + x + "</p>").join("");
2812         var div_infos = document.createElement("div");
2813         addClass(div_infos, "infos");
2814         div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;
2815
2816         container.appendChild(div_shortcuts);
2817         container.appendChild(div_infos);
2818
2819         popup.appendChild(container);
2820         insertAfter(popup, getSearchElement());
2821     }
2822
2823     onHashChange(null);
2824     window.onhashchange = onHashChange;
2825
2826     buildHelperPopup();
2827 }());
2828
2829 // This is required in firefox. Explanations: when going back in the history, firefox doesn't re-run
2830 // the JS, therefore preventing rustdoc from setting a few things required to be able to reload the
2831 // previous search results (if you navigated to a search result with the keyboard, pressed enter on
2832 // it to navigate to that result, and then came back to this page).
2833 window.onunload = function(){};