2 /* global ALIASES, currentCrate, rootPath */
4 // Local js definitions:
5 /* global addClass, getCurrentValue, hasClass */
6 /* global onEach, removeClass, updateLocalStorage */
8 if (!String.prototype.startsWith) {
9 String.prototype.startsWith = function(searchString, position) {
10 position = position || 0;
11 return this.indexOf(searchString, position) === position;
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;
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;
27 this.className = className;
33 if (!DOMTokenList.prototype.remove) {
34 DOMTokenList.prototype.remove = function(className) {
35 if (className && this.className) {
36 this.className = (" " + this.className + " ").replace(" " + className + " ", " ")
42 function getSearchInput() {
43 return document.getElementsByClassName("search-input")[0];
46 function getSearchElement() {
47 return document.getElementById("search");
53 // This mapping table should match the discriminants of
54 // `rustdoc::html::item_type::ItemType` type in Rust.
55 var itemTypes = ["mod",
82 var disableShortcuts = getCurrentValue("rustdoc-disable-shortcuts") === "true";
83 var search_input = getSearchInput();
85 // On the search screen, so you remain on the last tab you opened.
88 // 1 for "In Parameters"
89 // 2 for "In Return Types"
92 var titleBeforeSearch = document.title;
94 function getPageId() {
95 var id = document.location.href.split("#")[1];
97 return id.split("?")[0].split("&")[0];
102 function showSidebar() {
103 var elems = document.getElementsByClassName("sidebar-elems")[0];
105 addClass(elems, "show-it");
107 var sidebar = document.getElementsByClassName("sidebar")[0];
109 addClass(sidebar, "mobile");
110 var filler = document.getElementById("sidebar-filler");
112 var div = document.createElement("div");
113 div.id = "sidebar-filler";
114 sidebar.appendChild(div);
117 var themePickers = document.getElementsByClassName("theme-picker");
118 if (themePickers && themePickers.length > 0) {
119 themePickers[0].style.display = "none";
123 function hideSidebar() {
124 var elems = document.getElementsByClassName("sidebar-elems")[0];
126 removeClass(elems, "show-it");
128 var sidebar = document.getElementsByClassName("sidebar")[0];
129 removeClass(sidebar, "mobile");
130 var filler = document.getElementById("sidebar-filler");
134 document.getElementsByTagName("body")[0].style.marginTop = "";
135 var themePickers = document.getElementsByClassName("theme-picker");
136 if (themePickers && themePickers.length > 0) {
137 themePickers[0].style.display = null;
141 function showSearchResults(search) {
142 if (search === null || typeof search === 'undefined') {
143 search = getSearchElement();
145 addClass(main, "hidden");
146 removeClass(search, "hidden");
149 function hideSearchResults(search) {
150 if (search === null || typeof search === 'undefined') {
151 search = getSearchElement();
153 addClass(search, "hidden");
154 removeClass(main, "hidden");
157 // used for special search precedence
158 var TY_PRIMITIVE = itemTypes.indexOf("primitive");
159 var TY_KEYWORD = itemTypes.indexOf("keyword");
161 function getQueryStringParams() {
163 window.location.search.substring(1).split("&").
165 var pair = s.split("=");
166 params[decodeURIComponent(pair[0])] =
167 typeof pair[1] === "undefined" ? null : decodeURIComponent(pair[1]);
172 function browserSupportsHistoryApi() {
173 return window.history && typeof window.history.pushState === "function";
176 function isHidden(elem) {
177 return elem.offsetHeight === 0;
180 var main = document.getElementById("main");
183 function handleHashes(ev) {
184 var search = getSearchElement();
185 if (ev !== null && search && !hasClass(search, "hidden") && ev.newURL) {
186 // This block occurs when clicking on an element in the navbar while
188 hideSearchResults(search);
189 var hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1);
190 if (browserSupportsHistoryApi()) {
191 history.replaceState(hash, "", "?search=#" + hash);
193 var elem = document.getElementById(hash);
195 elem.scrollIntoView();
198 // This part is used in case an element is not visible.
199 if (savedHash !== window.location.hash) {
200 savedHash = window.location.hash;
201 if (savedHash.length === 0) {
204 var elem = document.getElementById(savedHash.slice(1)); // we remove the '#'
205 if (!elem || !isHidden(elem)) {
208 var parent = elem.parentNode;
209 if (parent && hasClass(parent, "impl-items")) {
210 // In case this is a trait implementation item, we first need to toggle
211 // the "Show hidden undocumented items".
212 onEachLazy(parent.getElementsByClassName("collapsed"), function(e) {
213 if (e.parentNode === parent) {
214 // Only click on the toggle we're looking for.
219 if (isHidden(elem)) {
220 // The whole parent is collapsed. We need to click on its toggle as well!
221 if (hasClass(parent.lastElementChild, "collapse-toggle")) {
222 parent.lastElementChild.click();
229 function highlightSourceLines(match, ev) {
230 if (typeof match === "undefined") {
231 // If we're in mobile mode, we should hide the sidebar in any case.
233 match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
238 var from = parseInt(match[1], 10);
240 if (typeof match[2] !== "undefined") {
241 to = parseInt(match[2], 10);
248 var elem = document.getElementById(from);
253 var x = document.getElementById(from);
258 onEachLazy(document.getElementsByClassName("line-numbers"), function(e) {
259 onEachLazy(e.getElementsByTagName("span"), function(i_e) {
260 removeClass(i_e, "line-highlighted");
263 for (var i = from; i <= to; ++i) {
264 elem = document.getElementById(i);
268 addClass(elem, "line-highlighted");
272 function onHashChange(ev) {
273 // If we're in mobile mode, we should hide the sidebar in any case.
275 var match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
277 return highlightSourceLines(match, ev);
282 function expandSection(id) {
283 var elem = document.getElementById(id);
284 if (elem && isHidden(elem)) {
285 var h3 = elem.parentNode.previousElementSibling;
286 if (h3 && h3.tagName !== "H3") {
287 h3 = h3.previousElementSibling; // skip div.docblock
291 var collapses = h3.getElementsByClassName("collapse-toggle");
292 if (collapses.length > 0) {
293 // The element is not visible, we need to make it appear!
294 collapseDocs(collapses[0], "show");
300 // Gets the human-readable string for the virtual-key code of the
301 // given KeyboardEvent, ev.
303 // This function is meant as a polyfill for KeyboardEvent#key,
304 // since it is not supported in Trident. We also test for
305 // KeyboardEvent#keyCode because the handleShortcut handler is
306 // also registered for the keydown event, because Blink doesn't fire
307 // keypress on hitting the Escape key.
309 // So I guess you could say things are getting pretty interoperable.
310 function getVirtualKey(ev) {
311 if ("key" in ev && typeof ev.key != "undefined") {
315 var c = ev.charCode || ev.keyCode;
319 return String.fromCharCode(c);
322 function getHelpElement() {
323 return document.getElementById("help");
326 function displayHelp(display, ev, help) {
327 var help = help ? help : getHelpElement();
328 if (display === true) {
329 if (hasClass(help, "hidden")) {
331 removeClass(help, "hidden");
332 addClass(document.body, "blur");
334 } else if (hasClass(help, "hidden") === false) {
336 addClass(help, "hidden");
337 removeClass(document.body, "blur");
341 function handleEscape(ev) {
342 var help = getHelpElement();
343 var search = getSearchElement();
344 if (hasClass(help, "hidden") === false) {
345 displayHelp(false, ev, help);
346 } else if (hasClass(search, "hidden") === false) {
348 hideSearchResults(search);
349 document.title = titleBeforeSearch;
354 function handleShortcut(ev) {
355 // Don't interfere with browser shortcuts
356 if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts === true) {
360 if (document.activeElement.tagName === "INPUT") {
361 switch (getVirtualKey(ev)) {
367 switch (getVirtualKey(ev)) {
374 displayHelp(false, ev);
387 displayHelp(true, ev);
394 function findParentElement(elem, tagName) {
396 if (elem && elem.tagName === tagName) {
399 elem = elem.parentNode;
404 document.addEventListener("keypress", handleShortcut);
405 document.addEventListener("keydown", handleShortcut);
407 var handleSourceHighlight = (function() {
408 var prev_line_id = 0;
410 var set_fragment = function(name) {
411 var x = window.scrollX,
413 if (browserSupportsHistoryApi()) {
414 history.replaceState(null, null, "#" + name);
415 highlightSourceLines();
417 location.replace("#" + name);
419 // Prevent jumps when selecting one or many lines
420 window.scrollTo(x, y);
423 return function(ev) {
424 var cur_line_id = parseInt(ev.target.id, 10);
427 if (ev.shiftKey && prev_line_id) {
428 // Swap selection if needed
429 if (prev_line_id > cur_line_id) {
430 var tmp = prev_line_id;
431 prev_line_id = cur_line_id;
435 set_fragment(prev_line_id + "-" + cur_line_id);
437 prev_line_id = cur_line_id;
439 set_fragment(cur_line_id);
444 document.addEventListener("click", function(ev) {
445 if (hasClass(ev.target, "collapse-toggle")) {
446 collapseDocs(ev.target, "toggle");
447 } else if (hasClass(ev.target.parentNode, "collapse-toggle")) {
448 collapseDocs(ev.target.parentNode, "toggle");
449 } else if (ev.target.tagName === "SPAN" && hasClass(ev.target.parentNode, "line-numbers")) {
450 handleSourceHighlight(ev);
451 } else if (hasClass(getHelpElement(), "hidden") === false) {
452 var help = getHelpElement();
453 var is_inside_help_popup = ev.target !== help && help.contains(ev.target);
454 if (is_inside_help_popup === false) {
455 addClass(help, "hidden");
456 removeClass(document.body, "blur");
459 // Making a collapsed element visible on onhashchange seems
461 var a = findParentElement(ev.target, "A");
463 expandSection(a.hash.replace(/^#/, ""));
468 var x = document.getElementsByClassName("version-selector");
470 x[0].onchange = function() {
472 url = document.location.href,
474 len = rootPath.match(/\.\.\//g).length + 1;
476 for (i = 0; i < len; ++i) {
477 match = url.match(/\/[^\/]*$/);
479 stripped = match[0] + stripped;
481 url = url.substring(0, url.length - match[0].length);
484 url += "/" + document.getElementsByClassName("version-selector")[0].value + stripped;
486 document.location.href = url;
491 * A function to compute the Levenshtein distance between two strings
492 * Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported
493 * Full License can be found at http://creativecommons.org/licenses/by-sa/3.0/legalcode
494 * This code is an unmodified version of the code written by Marco de Wit
495 * and was found at http://stackoverflow.com/a/18514751/745719
497 var levenshtein_row2 = [];
498 function levenshtein(s1, s2) {
502 var s1_len = s1.length, s2_len = s2.length;
503 if (s1_len && s2_len) {
504 var i1 = 0, i2 = 0, a, b, c, c2, row = levenshtein_row2;
505 while (i1 < s1_len) {
508 while (i2 < s2_len) {
509 c2 = s2.charCodeAt(i2);
513 for (i1 = 0; i1 < s1_len; ++i1) {
514 c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0);
516 b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c);
522 return s1_len + s2_len;
525 function initSearch(rawSearchIndex) {
526 var MAX_LEV_DISTANCE = 3;
527 var MAX_RESULTS = 200;
528 var GENERICS_DATA = 1;
532 var NO_TYPE_FILTER = -1;
533 var currentResults, index, searchIndex;
534 var params = getQueryStringParams();
536 // Populate search bar with query string search term when provided,
537 // but only if the input bar is empty. This avoid the obnoxious issue
538 // where you start trying to do a search, and the index loads, and
539 // suddenly your search is gone!
540 if (search_input.value === "") {
541 search_input.value = params.search || "";
545 * Executes the query and builds an index of results
546 * @param {[Object]} query [The user query]
547 * @param {[type]} searchWords [The list of search words to query
549 * @param {[type]} filterCrates [Crate to search in if defined]
550 * @return {[type]} [A search index of results]
552 function execQuery(query, searchWords, filterCrates) {
553 function itemTypeFromName(typename) {
554 var length = itemTypes.length;
555 for (var i = 0; i < length; ++i) {
556 if (itemTypes[i] === typename) {
560 return NO_TYPE_FILTER;
563 var valLower = query.query.toLowerCase(),
565 typeFilter = itemTypeFromName(query.type),
566 results = {}, results_in_args = {}, results_returned = {},
567 split = valLower.split("::");
569 var length = split.length;
570 for (var z = 0; z < length; ++z) {
571 if (split[z] === "") {
577 function transformResults(results, isType) {
579 var length = results.length;
580 for (var i = 0; i < length; ++i) {
581 if (results[i].id > -1) {
582 var obj = searchIndex[results[i].id];
583 obj.lev = results[i].lev;
584 if (isType !== true || obj.type) {
585 var res = buildHrefAndPath(obj);
586 obj.displayPath = pathSplitter(res[0]);
587 obj.fullPath = obj.displayPath + obj.name;
588 // To be sure than it some items aren't considered as duplicate.
589 obj.fullPath += "|" + obj.ty;
592 if (out.length >= MAX_RESULTS) {
601 function sortResults(results, isType) {
603 for (var entry in results) {
604 if (results.hasOwnProperty(entry)) {
605 ar.push(results[entry]);
610 var nresults = results.length;
611 for (i = 0; i < nresults; ++i) {
612 results[i].word = searchWords[results[i].id];
613 results[i].item = searchIndex[results[i].id] || {};
615 // if there are no results then return to default and fail
616 if (results.length === 0) {
620 results.sort(function(aaa, bbb) {
623 // sort by exact match with regard to the last word (mismatch goes later)
624 a = (aaa.word !== val);
625 b = (bbb.word !== val);
626 if (a !== b) { return a - b; }
628 // Sort by non levenshtein results and then levenshtein results by the distance
629 // (less changes required to match means higher rankings)
632 if (a !== b) { return a - b; }
634 // sort by crate (non-current crate goes later)
635 a = (aaa.item.crate !== window.currentCrate);
636 b = (bbb.item.crate !== window.currentCrate);
637 if (a !== b) { return a - b; }
639 // sort by item name length (longer goes later)
642 if (a !== b) { return a - b; }
644 // sort by item name (lexicographically larger goes later)
647 if (a !== b) { return (a > b ? +1 : -1); }
649 // sort by index of keyword in item name (no literal occurrence goes later)
652 if (a !== b) { return a - b; }
653 // (later literal occurrence, if any, goes later)
656 if (a !== b) { return a - b; }
658 // special precedence for primitive and keyword pages
659 if ((aaa.item.ty === TY_PRIMITIVE && bbb.item.ty !== TY_KEYWORD) ||
660 (aaa.item.ty === TY_KEYWORD && bbb.item.ty !== TY_PRIMITIVE)) {
663 if ((bbb.item.ty === TY_PRIMITIVE && aaa.item.ty !== TY_PRIMITIVE) ||
664 (bbb.item.ty === TY_KEYWORD && aaa.item.ty !== TY_KEYWORD)) {
668 // sort by description (no description goes later)
669 a = (aaa.item.desc === "");
670 b = (bbb.item.desc === "");
671 if (a !== b) { return a - b; }
673 // sort by type (later occurrence in `itemTypes` goes later)
676 if (a !== b) { return a - b; }
678 // sort by path (lexicographically larger goes later)
681 if (a !== b) { return (a > b ? +1 : -1); }
687 var length = results.length;
688 for (i = 0; i < length; ++i) {
689 var result = results[i];
691 // this validation does not make sense when searching by types
692 if (result.dontValidate) {
695 var name = result.item.name.toLowerCase(),
696 path = result.item.path.toLowerCase(),
697 parent = result.item.parent;
699 if (isType !== true &&
700 validateResult(name, path, split, parent) === false)
705 return transformResults(results);
708 function extractGenerics(val) {
709 val = val.toLowerCase();
710 if (val.indexOf("<") !== -1) {
711 var values = val.substring(val.indexOf("<") + 1, val.lastIndexOf(">"));
713 name: val.substring(0, val.indexOf("<")),
714 generics: values.split(/\s*,\s*/),
723 function getObjectFromId(id) {
724 if (typeof id === "number") {
725 return searchIndex[id];
730 function checkGenerics(obj, val) {
731 // The names match, but we need to be sure that all generics kinda
733 var lev_distance = MAX_LEV_DISTANCE + 1;
734 if (val.generics.length > 0) {
735 if (obj.length > GENERICS_DATA &&
736 obj[GENERICS_DATA].length >= val.generics.length) {
737 var elems = obj[GENERICS_DATA].slice(0);
740 // We need to find the type that matches the most to remove it in order
742 var vlength = val.generics.length;
743 for (var y = 0; y < vlength; ++y) {
744 var lev = { pos: -1, lev: MAX_LEV_DISTANCE + 1};
745 var elength = elems.length;
746 var firstGeneric = getObjectFromId(val.generics[y]).name;
747 for (var x = 0; x < elength; ++x) {
748 var tmp_lev = levenshtein(getObjectFromId(elems[x]).name,
750 if (tmp_lev < lev.lev) {
755 if (lev.pos !== -1) {
756 elems.splice(lev.pos, 1);
757 lev_distance = Math.min(lev.lev, lev_distance);
761 return MAX_LEV_DISTANCE + 1;
764 return Math.ceil(total / done);
767 return MAX_LEV_DISTANCE + 1;
770 // Check for type name and type generics (if any).
771 function checkType(obj, val, literalSearch) {
772 var lev_distance = MAX_LEV_DISTANCE + 1;
774 if (obj[NAME] === val.name) {
775 if (literalSearch === true) {
776 if (val.generics && val.generics.length !== 0) {
777 if (obj.length > GENERICS_DATA &&
778 obj[GENERICS_DATA].length >= val.generics.length) {
779 var elems = obj[GENERICS_DATA].slice(0);
782 for (var y = 0; allFound === true && y < val.generics.length; ++y) {
784 var firstGeneric = getObjectFromId(val.generics[y]).name;
785 for (x = 0; allFound === false && x < elems.length; ++x) {
786 allFound = getObjectFromId(elems[x]).name === firstGeneric;
788 if (allFound === true) {
789 elems.splice(x - 1, 1);
792 if (allFound === true) {
801 // If the type has generics but don't match, then it won't return at this point.
802 // Otherwise, `checkGenerics` will return 0 and it'll return.
803 if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length !== 0) {
804 var tmp_lev = checkGenerics(obj, val);
805 if (tmp_lev <= MAX_LEV_DISTANCE) {
812 // Names didn't match so let's check if one of the generic types could.
813 if (literalSearch === true) {
814 if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) {
815 var length = obj[GENERICS_DATA].length;
816 for (x = 0; x < length; ++x) {
817 if (obj[GENERICS_DATA][x] === val.name) {
824 lev_distance = Math.min(levenshtein(obj[NAME], val.name), lev_distance);
825 if (lev_distance <= MAX_LEV_DISTANCE) {
826 // The generics didn't match but the name kinda did so we give it
827 // a levenshtein distance value that isn't *this* good so it goes
828 // into the search results but not too high.
829 lev_distance = Math.ceil((checkGenerics(obj, val) + lev_distance) / 2);
830 } else if (obj.length > GENERICS_DATA && obj[GENERICS_DATA].length > 0) {
831 // We can check if the type we're looking for is inside the generics!
832 var olength = obj[GENERICS_DATA].length;
833 for (x = 0; x < olength; ++x) {
834 lev_distance = Math.min(levenshtein(obj[GENERICS_DATA][x], val.name),
838 // Now whatever happens, the returned distance is "less good" so we should mark it
839 // as such, and so we add 1 to the distance to make it "less good".
840 return lev_distance + 1;
843 function findArg(obj, val, literalSearch, typeFilter) {
844 var lev_distance = MAX_LEV_DISTANCE + 1;
846 if (obj && obj.type && obj.type[INPUTS_DATA] && obj.type[INPUTS_DATA].length > 0) {
847 var length = obj.type[INPUTS_DATA].length;
848 for (var i = 0; i < length; i++) {
849 var tmp = obj.type[INPUTS_DATA][i];
850 if (typePassesFilter(typeFilter, tmp[1]) === false) {
853 tmp = checkType(tmp, val, literalSearch);
854 if (literalSearch === true) {
860 lev_distance = Math.min(tmp, lev_distance);
861 if (lev_distance === 0) {
866 return literalSearch === true ? false : lev_distance;
869 function checkReturned(obj, val, literalSearch, typeFilter) {
870 var lev_distance = MAX_LEV_DISTANCE + 1;
872 if (obj && obj.type && obj.type.length > OUTPUT_DATA) {
873 var ret = obj.type[OUTPUT_DATA];
874 if (typeof ret[0] === "string") {
877 for (var x = 0; x < ret.length; ++x) {
879 if (typePassesFilter(typeFilter, tmp[1]) === false) {
882 tmp = checkType(tmp, val, literalSearch);
883 if (literalSearch === true) {
889 lev_distance = Math.min(tmp, lev_distance);
890 if (lev_distance === 0) {
895 return literalSearch === true ? false : lev_distance;
898 function checkPath(contains, lastElem, ty) {
899 if (contains.length === 0) {
902 var ret_lev = MAX_LEV_DISTANCE + 1;
903 var path = ty.path.split("::");
905 if (ty.parent && ty.parent.name) {
906 path.push(ty.parent.name.toLowerCase());
909 var length = path.length;
910 var clength = contains.length;
911 if (clength > length) {
912 return MAX_LEV_DISTANCE + 1;
914 for (var i = 0; i < length; ++i) {
915 if (i + clength > length) {
920 for (var x = 0; x < clength; ++x) {
921 var lev = levenshtein(path[i + x], contains[x]);
922 if (lev > MAX_LEV_DISTANCE) {
928 if (aborted === false) {
929 ret_lev = Math.min(ret_lev, Math.round(lev_total / clength));
935 function typePassesFilter(filter, type) {
937 if (filter <= NO_TYPE_FILTER) return true;
940 if (filter === type) return true;
942 // Match related items
943 var name = itemTypes[type];
944 switch (itemTypes[filter]) {
946 return name === "associatedconstant";
948 return name === "method" || name === "tymethod";
950 return name === "primitive" || name === "associatedtype";
952 return name === "traitalias";
959 function generateId(ty) {
960 if (ty.parent && ty.parent.name) {
961 return itemTypes[ty.ty] + ty.path + ty.parent.name + ty.name;
963 return itemTypes[ty.ty] + ty.path + ty.name;
966 // quoted values mean literal search
967 var nSearchWords = searchWords.length;
973 if ((val.charAt(0) === "\"" || val.charAt(0) === "'") &&
974 val.charAt(val.length - 1) === val.charAt(0))
976 val = extractGenerics(val.substr(1, val.length - 2));
977 for (i = 0; i < nSearchWords; ++i) {
978 if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) {
981 in_args = findArg(searchIndex[i], val, true, typeFilter);
982 returned = checkReturned(searchIndex[i], val, true, typeFilter);
984 fullId = generateId(ty);
986 if (searchWords[i] === val.name
987 && typePassesFilter(typeFilter, searchIndex[i].ty)
988 && results[fullId] === undefined) {
995 if (in_args === true && results_in_args[fullId] === undefined) {
996 results_in_args[fullId] = {
1002 if (returned === true && results_returned[fullId] === undefined) {
1003 results_returned[fullId] = {
1010 query.inputs = [val];
1013 // searching by type
1014 } else if (val.search("->") > -1) {
1015 var trimmer = function(s) { return s.trim(); };
1016 var parts = val.split("->").map(trimmer);
1017 var input = parts[0];
1018 // sort inputs so that order does not matter
1019 var inputs = input.split(",").map(trimmer).sort();
1020 for (i = 0; i < inputs.length; ++i) {
1021 inputs[i] = extractGenerics(inputs[i]);
1023 var output = extractGenerics(parts[1]);
1025 for (i = 0; i < nSearchWords; ++i) {
1026 if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) {
1029 var type = searchIndex[i].type;
1030 ty = searchIndex[i];
1034 fullId = generateId(ty);
1036 // allow searching for void (no output) functions as well
1037 var typeOutput = type.length > OUTPUT_DATA ? type[OUTPUT_DATA].name : "";
1038 returned = checkReturned(ty, output, true, NO_TYPE_FILTER);
1039 if (output.name === "*" || returned === true) {
1041 var is_module = false;
1043 if (input === "*") {
1046 var allFound = true;
1047 for (var it = 0; allFound === true && it < inputs.length; it++) {
1048 allFound = checkType(type, inputs[it], true);
1052 if (in_args === true) {
1053 results_in_args[fullId] = {
1059 if (returned === true) {
1060 results_returned[fullId] = {
1066 if (is_module === true) {
1075 query.inputs = inputs.map(function(input) {
1078 query.output = output.name;
1080 query.inputs = [val];
1083 // gather matching search results up to a certain maximum
1084 val = val.replace(/\_/g, "");
1086 var valGenerics = extractGenerics(val);
1088 var paths = valLower.split("::");
1090 for (j = 0; j < paths.length; ++j) {
1091 if (paths[j] === "") {
1096 val = paths[paths.length - 1];
1097 var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1);
1101 for (j = 0; j < nSearchWords; ++j) {
1102 ty = searchIndex[j];
1103 if (!ty || (filterCrates !== undefined && ty.crate !== filterCrates)) {
1107 if (paths.length > 1) {
1108 lev = checkPath(contains, paths[paths.length - 1], ty);
1109 if (lev > MAX_LEV_DISTANCE) {
1111 } else if (lev > 0) {
1116 returned = MAX_LEV_DISTANCE + 1;
1117 in_args = MAX_LEV_DISTANCE + 1;
1119 // we want lev results to go lower than others
1120 lev = MAX_LEV_DISTANCE + 1;
1121 fullId = generateId(ty);
1123 if (searchWords[j].indexOf(split[i]) > -1 ||
1124 searchWords[j].indexOf(val) > -1 ||
1125 searchWords[j].replace(/_/g, "").indexOf(val) > -1)
1127 // filter type: ... queries
1128 if (typePassesFilter(typeFilter, ty.ty) && results[fullId] === undefined) {
1129 index = searchWords[j].replace(/_/g, "").indexOf(val);
1132 if ((lev = levenshtein(searchWords[j], val)) <= MAX_LEV_DISTANCE) {
1133 if (typePassesFilter(typeFilter, ty.ty) === false) {
1134 lev = MAX_LEV_DISTANCE + 1;
1139 in_args = findArg(ty, valGenerics, false, typeFilter);
1140 returned = checkReturned(ty, valGenerics, false, typeFilter);
1143 if (lev > 0 && val.length > 3 && searchWords[j].indexOf(val) > -1) {
1144 if (val.length < 6) {
1150 if (in_args <= MAX_LEV_DISTANCE) {
1151 if (results_in_args[fullId] === undefined) {
1152 results_in_args[fullId] = {
1158 results_in_args[fullId].lev =
1159 Math.min(results_in_args[fullId].lev, in_args);
1161 if (returned <= MAX_LEV_DISTANCE) {
1162 if (results_returned[fullId] === undefined) {
1163 results_returned[fullId] = {
1169 results_returned[fullId].lev =
1170 Math.min(results_returned[fullId].lev, returned);
1172 if (index !== -1 || lev <= MAX_LEV_DISTANCE) {
1173 if (index !== -1 && paths.length < 2) {
1176 if (results[fullId] === undefined) {
1183 results[fullId].lev = Math.min(results[fullId].lev, lev);
1189 "in_args": sortResults(results_in_args, true),
1190 "returned": sortResults(results_returned, true),
1191 "others": sortResults(results),
1193 if (ALIASES && ALIASES[window.currentCrate] &&
1194 ALIASES[window.currentCrate][query.raw]) {
1195 var aliases = ALIASES[window.currentCrate][query.raw];
1196 for (i = 0; i < aliases.length; ++i) {
1197 aliases[i].is_alias = true;
1198 aliases[i].alias = query.raw;
1199 aliases[i].path = aliases[i].p;
1200 var res = buildHrefAndPath(aliases[i]);
1201 aliases[i].displayPath = pathSplitter(res[0]);
1202 aliases[i].fullPath = aliases[i].displayPath + aliases[i].name;
1203 aliases[i].href = res[1];
1204 ret.others.unshift(aliases[i]);
1205 if (ret.others.length > MAX_RESULTS) {
1214 * Validate performs the following boolean logic. For example:
1215 * "File::open" will give IF A PARENT EXISTS => ("file" && "open")
1216 * exists in (name || path || parent) OR => ("file" && "open") exists in
1219 * This could be written functionally, but I wanted to minimise
1220 * functions on stack.
1222 * @param {[string]} name [The name of the result]
1223 * @param {[string]} path [The path of the result]
1224 * @param {[string]} keys [The keys to be used (["file", "open"])]
1225 * @param {[object]} parent [The parent of the result]
1226 * @return {[boolean]} [Whether the result is valid or not]
1228 function validateResult(name, path, keys, parent) {
1229 for (var i = 0; i < keys.length; ++i) {
1230 // each check is for validation so we negate the conditions and invalidate
1232 // check for an exact name match
1233 name.indexOf(keys[i]) > -1 ||
1234 // then an exact path match
1235 path.indexOf(keys[i]) > -1 ||
1236 // next if there is a parent, check for exact parent match
1237 (parent !== undefined && parent.name !== undefined &&
1238 parent.name.toLowerCase().indexOf(keys[i]) > -1) ||
1239 // lastly check to see if the name was a levenshtein match
1240 levenshtein(name, keys[i]) <= MAX_LEV_DISTANCE)) {
1247 function getQuery(raw) {
1248 var matches, type, query;
1251 matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i);
1253 type = matches[1].replace(/^const$/, "constant");
1254 query = query.substring(matches[0].length);
1265 function initSearchNav() {
1268 var click_func = function(e) {
1270 // to retrieve the real "owner" of the event.
1271 while (el.tagName !== "TR") {
1274 var dst = e.target.getElementsByTagName("a");
1275 if (dst.length < 1) {
1279 if (window.location.pathname === dst.pathname) {
1280 hideSearchResults();
1281 document.location.href = dst.href;
1284 var mouseover_func = function(e) {
1286 // to retrieve the real "owner" of the event.
1287 while (el.tagName !== "TR") {
1290 clearTimeout(hoverTimeout);
1291 hoverTimeout = setTimeout(function() {
1292 onEachLazy(document.getElementsByClassName("search-results"), function(e) {
1293 onEachLazy(e.getElementsByClassName("result"), function(i_e) {
1294 removeClass(i_e, "highlighted");
1297 addClass(el, "highlighted");
1300 onEachLazy(document.getElementsByClassName("search-results"), function(e) {
1301 onEachLazy(e.getElementsByClassName("result"), function(i_e) {
1302 i_e.onclick = click_func;
1303 i_e.onmouseover = mouseover_func;
1307 search_input.onkeydown = function(e) {
1308 // "actives" references the currently highlighted item in each search tab.
1309 // Each array in "actives" represents a tab.
1310 var actives = [[], [], []];
1311 // "current" is used to know which tab we're looking into.
1313 onEachLazy(document.getElementById("results").childNodes, function(e) {
1314 onEachLazy(e.getElementsByClassName("highlighted"), function(e) {
1315 actives[current].push(e);
1320 if (e.which === 38) { // up
1321 if (!actives[currentTab].length ||
1322 !actives[currentTab][0].previousElementSibling) {
1326 addClass(actives[currentTab][0].previousElementSibling, "highlighted");
1327 removeClass(actives[currentTab][0], "highlighted");
1328 } else if (e.which === 40) { // down
1329 if (!actives[currentTab].length) {
1330 var results = document.getElementById("results").childNodes;
1331 if (results.length > 0) {
1332 var res = results[currentTab].getElementsByClassName("result");
1333 if (res.length > 0) {
1334 addClass(res[0], "highlighted");
1337 } else if (actives[currentTab][0].nextElementSibling) {
1338 addClass(actives[currentTab][0].nextElementSibling, "highlighted");
1339 removeClass(actives[currentTab][0], "highlighted");
1341 } else if (e.which === 13) { // return
1342 if (actives[currentTab].length) {
1343 document.location.href =
1344 actives[currentTab][0].getElementsByTagName("a")[0].href;
1346 } else if (e.which === 9) { // tab
1348 printTab(currentTab > 0 ? currentTab - 1 : 2);
1350 printTab(currentTab > 1 ? 0 : currentTab + 1);
1353 } else if (e.which === 16) { // shift
1354 // Does nothing, it's just to avoid losing "focus" on the highlighted element.
1355 } else if (actives[currentTab].length > 0) {
1356 removeClass(actives[currentTab][0], "highlighted");
1361 function buildHrefAndPath(item) {
1364 var type = itemTypes[item.ty];
1365 var name = item.name;
1366 var path = item.path;
1368 if (type === "mod") {
1369 displayPath = path + "::";
1370 href = rootPath + path.replace(/::/g, "/") + "/" +
1371 name + "/index.html";
1372 } else if (type === "primitive" || type === "keyword") {
1374 href = rootPath + path.replace(/::/g, "/") +
1375 "/" + type + "." + name + ".html";
1376 } else if (type === "externcrate") {
1378 href = rootPath + name + "/index.html";
1379 } else if (item.parent !== undefined) {
1380 var myparent = item.parent;
1381 var anchor = "#" + type + "." + name;
1382 var parentType = itemTypes[myparent.ty];
1383 var pageType = parentType;
1384 var pageName = myparent.name;
1386 if (parentType === "primitive") {
1387 displayPath = myparent.name + "::";
1388 } else if (type === "structfield" && parentType === "variant") {
1389 // Structfields belonging to variants are special: the
1390 // final path element is the enum name.
1391 var splitPath = item.path.split("::");
1392 var enumName = splitPath.pop();
1393 path = splitPath.join("::");
1394 displayPath = path + "::" + enumName + "::" + myparent.name + "::";
1395 anchor = "#variant." + myparent.name + ".field." + name;
1397 pageName = enumName;
1399 displayPath = path + "::" + myparent.name + "::";
1401 href = rootPath + path.replace(/::/g, "/") +
1406 displayPath = item.path + "::";
1407 href = rootPath + item.path.replace(/::/g, "/") +
1408 "/" + type + "." + name + ".html";
1410 return [displayPath, href];
1413 function escape(content) {
1414 var h1 = document.createElement("h1");
1415 h1.textContent = content;
1416 return h1.innerHTML;
1419 function pathSplitter(path) {
1420 var tmp = "<span>" + path.replace(/::/g, "::</span><span>");
1421 if (tmp.endsWith("<span>")) {
1422 return tmp.slice(0, tmp.length - 6);
1427 function addTab(array, query, display) {
1428 var extraStyle = "";
1429 if (display === false) {
1430 extraStyle = " style=\"display: none;\"";
1434 var duplicates = {};
1436 if (array.length > 0) {
1437 output = "<table class=\"search-results\"" + extraStyle + ">";
1439 array.forEach(function(item) {
1443 type = itemTypes[item.ty];
1445 if (item.is_alias !== true) {
1446 if (duplicates[item.fullPath]) {
1449 duplicates[item.fullPath] = true;
1453 output += "<tr class=\"" + type + " result\"><td>" +
1454 "<a href=\"" + item.href + "\">" +
1455 (item.is_alias === true ?
1456 ("<span class=\"alias\"><b>" + item.alias + " </b></span><span " +
1457 "class=\"grey\"><i> - see </i></span>") : "") +
1458 item.displayPath + "<span class=\"" + type + "\">" +
1459 name + "</span></a></td><td>" +
1460 "<a href=\"" + item.href + "\">" +
1461 "<span class=\"desc\">" + escape(item.desc) +
1462 " </span></a></td></tr>";
1464 output += "</table>";
1466 output = "<div class=\"search-failed\"" + extraStyle + ">No results :(<br/>" +
1467 "Try on <a href=\"https://duckduckgo.com/?q=" +
1468 encodeURIComponent("rust " + query.query) +
1469 "\">DuckDuckGo</a>?<br/><br/>" +
1470 "Or try looking in one of these:<ul><li>The <a " +
1471 "href=\"https://doc.rust-lang.org/reference/index.html\">Rust Reference</a> " +
1472 " for technical details about the language.</li><li><a " +
1473 "href=\"https://doc.rust-lang.org/rust-by-example/index.html\">Rust By " +
1474 "Example</a> for expository code examples.</a></li><li>The <a " +
1475 "href=\"https://doc.rust-lang.org/book/index.html\">Rust Book</a> for " +
1476 "introductions to language features and the language itself.</li><li><a " +
1477 "href=\"https://docs.rs\">Docs.rs</a> for documentation of crates released on" +
1478 " <a href=\"https://crates.io/\">crates.io</a>.</li></ul></div>";
1480 return [output, length];
1483 function makeTabHeader(tabNb, text, nbElems) {
1484 if (currentTab === tabNb) {
1485 return "<div class=\"selected\">" + text +
1486 " <div class=\"count\">(" + nbElems + ")</div></div>";
1488 return "<div>" + text + " <div class=\"count\">(" + nbElems + ")</div></div>";
1491 function showResults(results) {
1492 if (results.others.length === 1 &&
1493 getCurrentValue("rustdoc-go-to-only-result") === "true") {
1494 var elem = document.createElement("a");
1495 elem.href = results.others[0].href;
1496 elem.style.display = "none";
1497 // For firefox, we need the element to be in the DOM so it can be clicked.
1498 document.body.appendChild(elem);
1501 var query = getQuery(search_input.value);
1503 currentResults = query.id;
1505 var ret_others = addTab(results.others, query);
1506 var ret_in_args = addTab(results.in_args, query, false);
1507 var ret_returned = addTab(results.returned, query, false);
1509 var output = "<h1>Results for " + escape(query.query) +
1510 (query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
1511 "<div id=\"titles\">" +
1512 makeTabHeader(0, "In Names", ret_others[1]) +
1513 makeTabHeader(1, "In Parameters", ret_in_args[1]) +
1514 makeTabHeader(2, "In Return Types", ret_returned[1]) +
1515 "</div><div id=\"results\">" +
1516 ret_others[0] + ret_in_args[0] + ret_returned[0] + "</div>";
1518 var search = getSearchElement();
1519 search.innerHTML = output;
1520 showSearchResults(search);
1521 var tds = search.getElementsByTagName("td");
1523 if (tds.length > 0) {
1524 td_width = tds[0].offsetWidth;
1526 var width = search.offsetWidth - 40 - td_width;
1527 onEachLazy(search.getElementsByClassName("desc"), function(e) {
1528 e.style.width = width + "px";
1531 var elems = document.getElementById("titles").childNodes;
1532 elems[0].onclick = function() { printTab(0); };
1533 elems[1].onclick = function() { printTab(1); };
1534 elems[2].onclick = function() { printTab(2); };
1535 printTab(currentTab);
1538 function execSearch(query, searchWords, filterCrates) {
1539 function getSmallest(arrays, positions, notDuplicates) {
1542 for (var it = 0; it < positions.length; ++it) {
1543 if (arrays[it].length > positions[it] &&
1544 (start === null || start > arrays[it][positions[it]].lev) &&
1545 !notDuplicates[arrays[it][positions[it]].fullPath]) {
1546 start = arrays[it][positions[it]].lev;
1552 function mergeArrays(arrays) {
1555 var notDuplicates = {};
1557 for (var x = 0; x < arrays.length; ++x) {
1560 while (ret.length < MAX_RESULTS) {
1561 var smallest = getSmallest(arrays, positions, notDuplicates);
1563 if (smallest === null) {
1566 for (x = 0; x < arrays.length && ret.length < MAX_RESULTS; ++x) {
1567 if (arrays[x].length > positions[x] &&
1568 arrays[x][positions[x]].lev === smallest &&
1569 !notDuplicates[arrays[x][positions[x]].fullPath]) {
1570 ret.push(arrays[x][positions[x]]);
1571 notDuplicates[arrays[x][positions[x]].fullPath] = true;
1579 var queries = query.raw.split(",");
1586 for (var i = 0; i < queries.length; ++i) {
1587 query = queries[i].trim();
1588 if (query.length !== 0) {
1589 var tmp = execQuery(getQuery(query), searchWords, filterCrates);
1591 results.in_args.push(tmp.in_args);
1592 results.returned.push(tmp.returned);
1593 results.others.push(tmp.others);
1596 if (queries.length > 1) {
1598 "in_args": mergeArrays(results.in_args),
1599 "returned": mergeArrays(results.returned),
1600 "others": mergeArrays(results.others),
1604 "in_args": results.in_args[0],
1605 "returned": results.returned[0],
1606 "others": results.others[0],
1611 function getFilterCrates() {
1612 var elem = document.getElementById("crate-search");
1614 if (elem && elem.value !== "All crates" && rawSearchIndex.hasOwnProperty(elem.value)) {
1620 function search(e, forced) {
1621 var params = getQueryStringParams();
1622 var query = getQuery(search_input.value.trim());
1628 if (query.query.length === 0) {
1631 if (forced !== true && query.id === currentResults) {
1632 if (query.query.length > 0) {
1633 putBackSearch(search_input);
1638 // Update document title to maintain a meaningful browser history
1639 document.title = "Results for " + query.query + " - Rust";
1641 // Because searching is incremental by character, only the most
1642 // recent search query is added to the browser history.
1643 if (browserSupportsHistoryApi()) {
1644 if (!history.state && !params.search) {
1645 history.pushState(query, "", "?search=" + encodeURIComponent(query.raw));
1647 history.replaceState(query, "", "?search=" + encodeURIComponent(query.raw));
1651 var filterCrates = getFilterCrates();
1652 showResults(execSearch(query, index, filterCrates));
1655 function buildIndex(rawSearchIndex) {
1657 var searchWords = [];
1660 for (var crate in rawSearchIndex) {
1661 if (!rawSearchIndex.hasOwnProperty(crate)) { continue; }
1663 searchWords.push(crate);
1666 ty: 1, // == ExternCrate
1669 desc: rawSearchIndex[crate].doc,
1673 // an array of [(Number) item type,
1675 // (String) full path or empty string for previous path,
1676 // (String) description,
1677 // (Number | null) the parent path index to `paths`]
1678 // (Object | null) the type of the function (if any)
1679 var items = rawSearchIndex[crate].i;
1680 // an array of [(Number) item type,
1682 var paths = rawSearchIndex[crate].p;
1684 // convert `rawPaths` entries into object form
1685 var len = paths.length;
1686 for (i = 0; i < len; ++i) {
1687 paths[i] = {ty: paths[i][0], name: paths[i][1]};
1690 // convert `items` into an object form, and construct word indices.
1692 // before any analysis is performed lets gather the search terms to
1693 // search against apart from the rest of the data. This is a quick
1694 // operation that is cached for the life of the page state so that
1695 // all other search operations have access to this cached data for
1696 // faster analysis operations
1699 for (i = 0; i < len; ++i) {
1700 var rawRow = items[i];
1701 var row = {crate: crate, ty: rawRow[0], name: rawRow[1],
1702 path: rawRow[2] || lastPath, desc: rawRow[3],
1703 parent: paths[rawRow[4]], type: rawRow[5]};
1704 searchIndex.push(row);
1705 if (typeof row.name === "string") {
1706 var word = row.name.toLowerCase();
1707 searchWords.push(word);
1709 searchWords.push("");
1711 lastPath = row.path;
1717 function startSearch() {
1719 var callback = function() {
1720 clearTimeout(searchTimeout);
1721 if (search_input.value.length === 0) {
1722 if (browserSupportsHistoryApi()) {
1723 history.replaceState("", window.currentCrate + " - Rust", "?search=");
1725 hideSearchResults();
1727 searchTimeout = setTimeout(search, 500);
1730 search_input.onkeyup = callback;
1731 search_input.oninput = callback;
1732 document.getElementsByClassName("search-form")[0].onsubmit = function(e) {
1734 clearTimeout(searchTimeout);
1737 search_input.onchange = function(e) {
1738 if (e.target !== document.activeElement) {
1739 // To prevent doing anything when it's from a blur event.
1742 // Do NOT e.preventDefault() here. It will prevent pasting.
1743 clearTimeout(searchTimeout);
1744 // zero-timeout necessary here because at the time of event handler execution the
1745 // pasted content is not in the input field yet. Shouldn’t make any difference for
1747 setTimeout(search, 0);
1749 search_input.onpaste = search_input.onchange;
1751 var selectCrate = document.getElementById("crate-search");
1753 selectCrate.onchange = function() {
1754 updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value);
1755 search(undefined, true);
1759 // Push and pop states are used to add search results to the browser
1761 if (browserSupportsHistoryApi()) {
1762 // Store the previous <title> so we can revert back to it later.
1763 var previousTitle = document.title;
1765 window.addEventListener("popstate", function(e) {
1766 var params = getQueryStringParams();
1767 // Revert to the previous title manually since the History
1768 // API ignores the title parameter.
1769 document.title = previousTitle;
1770 // When browsing forward to search results the previous
1771 // search will be repeated, so the currentResults are
1772 // cleared to ensure the search is successful.
1773 currentResults = null;
1774 // Synchronize search bar with query string state and
1775 // perform the search. This will empty the bar if there's
1776 // nothing there, which lets you really go back to a
1777 // previous state with nothing in the bar.
1778 if (params.search && params.search.length > 0) {
1779 search_input.value = params.search;
1780 // Some browsers fire "onpopstate" for every page load
1781 // (Chrome), while others fire the event only when actually
1782 // popping a state (Firefox), which is why search() is
1783 // called both here and at the end of the startSearch()
1787 search_input.value = "";
1788 // When browsing back from search results the main page
1789 // visibility must be reset.
1790 hideSearchResults();
1797 index = buildIndex(rawSearchIndex);
1800 // Draw a convenient sidebar of known crates if we have a listing
1801 if (rootPath === "../" || rootPath === "./") {
1802 var sidebar = document.getElementsByClassName("sidebar-elems")[0];
1804 var div = document.createElement("div");
1805 div.className = "block crate";
1806 div.innerHTML = "<h3>Crates</h3>";
1807 var ul = document.createElement("ul");
1808 div.appendChild(ul);
1811 for (var crate in rawSearchIndex) {
1812 if (!rawSearchIndex.hasOwnProperty(crate)) {
1818 for (var i = 0; i < crates.length; ++i) {
1819 var klass = "crate";
1820 if (rootPath !== "./" && crates[i] === window.currentCrate) {
1821 klass += " current";
1823 var link = document.createElement("a");
1824 link.href = rootPath + crates[i] + "/index.html";
1825 link.title = rawSearchIndex[crates[i]].doc;
1826 link.className = klass;
1827 link.textContent = crates[i];
1829 var li = document.createElement("li");
1830 li.appendChild(link);
1833 sidebar.appendChild(div);
1838 window.initSearch = initSearch;
1840 // delayed sidebar rendering.
1841 function initSidebarItems(items) {
1842 var sidebar = document.getElementsByClassName("sidebar-elems")[0];
1843 var current = window.sidebarCurrent;
1845 function block(shortty, longty) {
1846 var filtered = items[shortty];
1851 var div = document.createElement("div");
1852 div.className = "block " + shortty;
1853 var h3 = document.createElement("h3");
1854 h3.textContent = longty;
1855 div.appendChild(h3);
1856 var ul = document.createElement("ul");
1858 var length = filtered.length;
1859 for (var i = 0; i < length; ++i) {
1860 var item = filtered[i];
1862 var desc = item[1]; // can be null
1864 var klass = shortty;
1865 if (name === current.name && shortty === current.ty) {
1866 klass += " current";
1869 if (shortty === "mod") {
1870 path = name + "/index.html";
1872 path = shortty + "." + name + ".html";
1874 var link = document.createElement("a");
1875 link.href = current.relpath + path;
1877 link.className = klass;
1878 link.textContent = name;
1879 var li = document.createElement("li");
1880 li.appendChild(link);
1883 div.appendChild(ul);
1885 sidebar.appendChild(div);
1889 block("primitive", "Primitive Types");
1890 block("mod", "Modules");
1891 block("macro", "Macros");
1892 block("struct", "Structs");
1893 block("enum", "Enums");
1894 block("union", "Unions");
1895 block("constant", "Constants");
1896 block("static", "Statics");
1897 block("trait", "Traits");
1898 block("fn", "Functions");
1899 block("type", "Type Definitions");
1900 block("foreigntype", "Foreign Types");
1901 block("keyword", "Keywords");
1902 block("traitalias", "Trait Aliases");
1905 window.initSidebarItems = initSidebarItems;
1907 window.register_implementors = function(imp) {
1908 var implementors = document.getElementById("implementors-list");
1909 var synthetic_implementors = document.getElementById("synthetic-implementors-list");
1911 if (synthetic_implementors) {
1912 // This `inlined_types` variable is used to avoid having the same implementation
1913 // showing up twice. For example "String" in the "Sync" doc page.
1915 // By the way, this is only used by and useful for traits implemented automatically
1916 // (like "Send" and "Sync").
1917 var inlined_types = new Set();
1918 onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) {
1919 var aliases = el.getAttribute("aliases");
1923 aliases.split(",").forEach(function(alias) {
1924 inlined_types.add(alias);
1929 var libs = Object.getOwnPropertyNames(imp);
1930 var llength = libs.length;
1931 for (var i = 0; i < llength; ++i) {
1932 if (libs[i] === currentCrate) { continue; }
1933 var structs = imp[libs[i]];
1935 var slength = structs.length;
1937 for (var j = 0; j < slength; ++j) {
1938 var struct = structs[j];
1940 var list = struct.synthetic ? synthetic_implementors : implementors;
1942 if (struct.synthetic) {
1943 var stlength = struct.types.length;
1944 for (var k = 0; k < stlength; k++) {
1945 if (inlined_types.has(struct.types[k])) {
1946 continue struct_loop;
1948 inlined_types.add(struct.types[k]);
1952 var code = document.createElement("code");
1953 code.innerHTML = struct.text;
1955 var x = code.getElementsByTagName("a");
1956 var xlength = x.length;
1957 for (var it = 0; it < xlength; it++) {
1958 var href = x[it].getAttribute("href");
1959 if (href && href.indexOf("http") !== 0) {
1960 x[it].setAttribute("href", rootPath + href);
1963 var display = document.createElement("h3");
1964 addClass(display, "impl");
1965 display.innerHTML = "<span class=\"in-band\"><table class=\"table-display\">" +
1966 "<tbody><tr><td><code>" + code.outerHTML + "</code></td><td></td></tr>" +
1967 "</tbody></table></span>";
1968 list.appendChild(display);
1972 if (window.pending_implementors) {
1973 window.register_implementors(window.pending_implementors);
1976 function labelForToggleButton(sectionIsCollapsed) {
1977 if (sectionIsCollapsed) {
1978 // button will expand the section
1981 // button will collapse the section
1982 // note that this text is also set in the HTML template in render.rs
1983 return "\u2212"; // "\u2212" is "−" minus sign
1986 function onEveryMatchingChild(elem, className, func) {
1987 if (elem && className && func) {
1988 var length = elem.childNodes.length;
1989 var nodes = elem.childNodes;
1990 for (var i = 0; i < length; ++i) {
1991 if (hasClass(nodes[i], className)) {
1994 onEveryMatchingChild(nodes[i], className, func);
2000 function toggleAllDocs(pageId, fromAutoCollapse) {
2001 var innerToggle = document.getElementById("toggle-all-docs");
2005 if (hasClass(innerToggle, "will-expand")) {
2006 updateLocalStorage("rustdoc-collapse", "false");
2007 removeClass(innerToggle, "will-expand");
2008 onEveryMatchingChild(innerToggle, "inner", function(e) {
2009 e.innerHTML = labelForToggleButton(false);
2011 innerToggle.title = "collapse all docs";
2012 if (fromAutoCollapse !== true) {
2013 onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
2014 collapseDocs(e, "show");
2018 updateLocalStorage("rustdoc-collapse", "true");
2019 addClass(innerToggle, "will-expand");
2020 onEveryMatchingChild(innerToggle, "inner", function(e) {
2021 var parent = e.parentNode;
2022 var superParent = null;
2025 superParent = parent.parentNode;
2027 if (!parent || !superParent || superParent.id !== "main" ||
2028 hasClass(parent, "impl") === false) {
2029 e.innerHTML = labelForToggleButton(true);
2032 innerToggle.title = "expand all docs";
2033 if (fromAutoCollapse !== true) {
2034 onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
2035 var parent = e.parentNode;
2036 var superParent = null;
2039 superParent = parent.parentNode;
2041 if (!parent || !superParent || superParent.id !== "main" ||
2042 hasClass(parent, "impl") === false) {
2043 collapseDocs(e, "hide", pageId);
2050 function collapseDocs(toggle, mode, pageId) {
2051 if (!toggle || !toggle.parentNode) {
2055 function adjustToggle(arg) {
2056 return function(e) {
2057 if (hasClass(e, "toggle-label")) {
2059 e.style.display = "inline-block";
2061 e.style.display = "none";
2064 if (hasClass(e, "inner")) {
2065 e.innerHTML = labelForToggleButton(arg);
2070 function implHider(addOrRemove, fullHide) {
2071 return function(n) {
2072 var is_method = hasClass(n, "method") || fullHide;
2073 if (is_method || hasClass(n, "type")) {
2074 if (is_method === true) {
2076 addClass(n, "hidden-by-impl-hider");
2078 removeClass(n, "hidden-by-impl-hider");
2081 var ns = n.nextElementSibling;
2084 hasClass(ns, "docblock") ||
2085 hasClass(ns, "stability"))) {
2087 addClass(ns, "hidden-by-impl-hider");
2089 removeClass(ns, "hidden-by-impl-hider");
2091 ns = ns.nextElementSibling;
2102 if (hasClass(toggle.parentNode, "impl") === false) {
2103 relatedDoc = toggle.parentNode.nextElementSibling;
2104 if (hasClass(relatedDoc, "stability")) {
2105 relatedDoc = relatedDoc.nextElementSibling;
2107 if (hasClass(relatedDoc, "docblock") || hasClass(relatedDoc, "sub-variant")) {
2108 if (mode === "toggle") {
2109 if (hasClass(relatedDoc, "hidden-by-usual-hider")) {
2115 if (action === "hide") {
2116 addClass(relatedDoc, "hidden-by-usual-hider");
2117 onEachLazy(toggle.childNodes, adjustToggle(true));
2118 addClass(toggle.parentNode, "collapsed");
2119 } else if (action === "show") {
2120 removeClass(relatedDoc, "hidden-by-usual-hider");
2121 removeClass(toggle.parentNode, "collapsed");
2122 onEachLazy(toggle.childNodes, adjustToggle(false));
2126 // we are collapsing the impl block(s).
2128 var parentElem = toggle.parentNode;
2129 relatedDoc = parentElem;
2130 var docblock = relatedDoc.nextElementSibling;
2132 while (hasClass(relatedDoc, "impl-items") === false) {
2133 relatedDoc = relatedDoc.nextElementSibling;
2136 if ((!relatedDoc && hasClass(docblock, "docblock") === false) ||
2137 (pageId && document.getElementById(pageId))) {
2141 // Hide all functions, but not associated types/consts.
2143 if (mode === "toggle") {
2144 if (hasClass(relatedDoc, "fns-now-collapsed") ||
2145 hasClass(docblock, "hidden-by-impl-hider")) {
2152 var dontApplyBlockRule = toggle.parentNode.parentNode.id !== "main";
2153 if (action === "show") {
2154 removeClass(relatedDoc, "fns-now-collapsed");
2155 removeClass(docblock, "hidden-by-usual-hider");
2156 onEachLazy(toggle.childNodes, adjustToggle(false, dontApplyBlockRule));
2157 onEachLazy(relatedDoc.childNodes, implHider(false, dontApplyBlockRule));
2158 } else if (action === "hide") {
2159 addClass(relatedDoc, "fns-now-collapsed");
2160 addClass(docblock, "hidden-by-usual-hider");
2161 onEachLazy(toggle.childNodes, adjustToggle(true, dontApplyBlockRule));
2162 onEachLazy(relatedDoc.childNodes, implHider(true, dontApplyBlockRule));
2167 function collapser(e, collapse) {
2168 // inherent impl ids are like "impl" or impl-<number>'.
2169 // they will never be hidden by default.
2170 var n = e.parentElement;
2171 if (n.id.match(/^impl(?:-\d+)?$/) === null) {
2172 // Automatically minimize all non-inherent impls
2173 if (collapse || hasClass(n, "impl")) {
2174 collapseDocs(e, "hide", pageId);
2179 function autoCollapse(pageId, collapse) {
2181 toggleAllDocs(pageId, true);
2182 } else if (getCurrentValue("rustdoc-auto-hide-trait-implementations") !== "false") {
2183 var impl_list = document.getElementById("implementations-list");
2185 if (impl_list !== null) {
2186 onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
2187 collapser(e, collapse);
2191 var blanket_list = document.getElementById("blanket-implementations-list");
2193 if (blanket_list !== null) {
2194 onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
2195 collapser(e, collapse);
2201 var toggles = document.getElementById("toggle-all-docs");
2203 toggles.onclick = toggleAllDocs;
2206 function insertAfter(newNode, referenceNode) {
2207 referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
2210 function createSimpleToggle(sectionIsCollapsed) {
2211 var toggle = document.createElement("a");
2212 toggle.href = "javascript:void(0)";
2213 toggle.className = "collapse-toggle";
2214 toggle.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(sectionIsCollapsed) +
2219 var toggle = createSimpleToggle(false);
2220 var hideMethodDocs = getCurrentValue("rustdoc-auto-hide-method-docs") === "true";
2221 var pageId = getPageId();
2223 var func = function(e) {
2224 var next = e.nextElementSibling;
2228 if (hasClass(next, "docblock") === true ||
2229 (hasClass(next, "stability") === true &&
2230 hasClass(next.nextElementSibling, "docblock") === true)) {
2231 var newToggle = toggle.cloneNode(true);
2232 insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
2233 if (hideMethodDocs === true && hasClass(e, "method") === true) {
2234 collapseDocs(newToggle, "hide", pageId);
2239 var funcImpl = function(e) {
2240 var next = e.nextElementSibling;
2241 if (next && hasClass(next, "docblock")) {
2242 next = next.nextElementSibling;
2247 if (next.getElementsByClassName("method").length > 0 && hasClass(e, "impl")) {
2248 insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
2252 onEachLazy(document.getElementsByClassName("method"), func);
2253 onEachLazy(document.getElementsByClassName("associatedconstant"), func);
2254 onEachLazy(document.getElementsByClassName("impl"), funcImpl);
2255 var impl_call = function() {};
2256 if (hideMethodDocs === true) {
2257 impl_call = function(e, newToggle, pageId) {
2258 if (e.id.match(/^impl(?:-\d+)?$/) === null) {
2259 // Automatically minimize all non-inherent impls
2260 if (hasClass(e, "impl") === true) {
2261 collapseDocs(newToggle, "hide", pageId);
2266 var newToggle = document.createElement("a");
2267 newToggle.href = "javascript:void(0)";
2268 newToggle.className = "collapse-toggle hidden-default collapsed";
2269 newToggle.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(true) +
2270 "</span>] Show hidden undocumented items";
2271 function toggleClicked() {
2272 if (hasClass(this, "collapsed")) {
2273 removeClass(this, "collapsed");
2274 onEachLazy(this.parentNode.getElementsByClassName("hidden"), function(x) {
2275 if (hasClass(x, "content") === false) {
2276 removeClass(x, "hidden");
2280 this.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(false) +
2281 "</span>] Hide undocumented items";
2283 addClass(this, "collapsed");
2284 onEachLazy(this.parentNode.getElementsByClassName("x"), function(x) {
2285 if (hasClass(x, "content") === false) {
2286 addClass(x, "hidden");
2287 removeClass(x, "x");
2290 this.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(true) +
2291 "</span>] Show hidden undocumented items";
2294 onEachLazy(document.getElementsByClassName("impl-items"), function(e) {
2295 onEachLazy(e.getElementsByClassName("associatedconstant"), func);
2296 var hiddenElems = e.getElementsByClassName("hidden");
2297 var needToggle = false;
2299 var hlength = hiddenElems.length;
2300 for (var i = 0; i < hlength; ++i) {
2301 if (hasClass(hiddenElems[i], "content") === false &&
2302 hasClass(hiddenElems[i], "docblock") === false) {
2307 if (needToggle === true) {
2308 var inner_toggle = newToggle.cloneNode(true);
2309 inner_toggle.onclick = toggleClicked;
2310 e.insertBefore(inner_toggle, e.firstChild);
2311 impl_call(e.previousSibling, inner_toggle, pageId);
2315 function createToggle(otherMessage, fontSize, extraClass, show) {
2316 var span = document.createElement("span");
2317 span.className = "toggle-label";
2319 span.style.display = "none";
2321 if (!otherMessage) {
2322 span.innerHTML = " Expand description";
2324 span.innerHTML = otherMessage;
2328 span.style.fontSize = fontSize;
2331 var mainToggle = toggle.cloneNode(true);
2332 mainToggle.appendChild(span);
2334 var wrapper = document.createElement("div");
2335 wrapper.className = "toggle-wrapper";
2337 addClass(wrapper, "collapsed");
2338 var inner = mainToggle.getElementsByClassName("inner");
2339 if (inner && inner.length > 0) {
2340 inner[0].innerHTML = "+";
2344 addClass(wrapper, extraClass);
2346 wrapper.appendChild(mainToggle);
2350 var currentType = document.getElementsByClassName("type-decl")[0];
2351 var className = null;
2353 currentType = currentType.getElementsByClassName("rust")[0];
2355 currentType.classList.forEach(function(item) {
2356 if (item !== "main") {
2363 var showItemDeclarations = getCurrentValue("rustdoc-auto-hide-" + className);
2364 if (showItemDeclarations === null) {
2365 if (className === "enum" || className === "macro") {
2366 showItemDeclarations = "false";
2367 } else if (className === "struct" || className === "union" || className === "trait") {
2368 showItemDeclarations = "true";
2370 // In case we found an unknown type, we just use the "parent" value.
2371 showItemDeclarations = getCurrentValue("rustdoc-auto-hide-declarations");
2374 showItemDeclarations = showItemDeclarations === "false";
2375 function buildToggleWrapper(e) {
2376 if (hasClass(e, "autohide")) {
2377 var wrap = e.previousElementSibling;
2378 if (wrap && hasClass(wrap, "toggle-wrapper")) {
2379 var inner_toggle = wrap.childNodes[0];
2380 var extra = e.childNodes[0].tagName === "H3";
2382 e.style.display = "none";
2383 addClass(wrap, "collapsed");
2384 onEachLazy(inner_toggle.getElementsByClassName("inner"), function(e) {
2385 e.innerHTML = labelForToggleButton(true);
2387 onEachLazy(inner_toggle.getElementsByClassName("toggle-label"), function(e) {
2388 e.style.display = "inline-block";
2389 if (extra === true) {
2390 i_e.innerHTML = " Show " + e.childNodes[0].innerHTML;
2395 if (e.parentNode.id === "main") {
2396 var otherMessage = "";
2400 if (hasClass(e, "type-decl")) {
2402 otherMessage = " Show declaration";
2403 if (showItemDeclarations === false) {
2404 extraClass = "collapsed";
2406 } else if (hasClass(e, "sub-variant")) {
2407 otherMessage = " Show fields";
2408 } else if (hasClass(e, "non-exhaustive")) {
2409 otherMessage = " This ";
2410 if (hasClass(e, "non-exhaustive-struct")) {
2411 otherMessage += "struct";
2412 } else if (hasClass(e, "non-exhaustive-enum")) {
2413 otherMessage += "enum";
2414 } else if (hasClass(e, "non-exhaustive-variant")) {
2415 otherMessage += "enum variant";
2416 } else if (hasClass(e, "non-exhaustive-type")) {
2417 otherMessage += "type";
2419 otherMessage += " is marked as non-exhaustive";
2420 } else if (hasClass(e.childNodes[0], "impl-items")) {
2421 extraClass = "marg-left";
2424 e.parentNode.insertBefore(
2425 createToggle(otherMessage,
2428 hasClass(e, "type-decl") === false || showItemDeclarations === true),
2430 if (hasClass(e, "type-decl") === true && showItemDeclarations === true) {
2431 collapseDocs(e.previousSibling.childNodes[0], "toggle");
2433 if (hasClass(e, "non-exhaustive") === true) {
2434 collapseDocs(e.previousSibling.childNodes[0], "toggle");
2439 onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
2440 onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
2442 function createToggleWrapper(tog) {
2443 var span = document.createElement("span");
2444 span.className = "toggle-label";
2445 span.style.display = "none";
2446 span.innerHTML = " Expand attributes";
2447 tog.appendChild(span);
2449 var wrapper = document.createElement("div");
2450 wrapper.className = "toggle-wrapper toggle-attributes";
2451 wrapper.appendChild(tog);
2455 // To avoid checking on "rustdoc-item-attributes" value on every loop...
2456 var itemAttributesFunc = function() {};
2457 if (getCurrentValue("rustdoc-auto-hide-attributes") !== "false") {
2458 itemAttributesFunc = function(x) {
2459 collapseDocs(x.previousSibling.childNodes[0], "toggle");
2462 var attributesToggle = createToggleWrapper(createSimpleToggle(false));
2463 onEachLazy(main.getElementsByClassName("attributes"), function(i_e) {
2464 var attr_tog = attributesToggle.cloneNode(true);
2465 if (hasClass(i_e, "top-attr") === true) {
2466 addClass(attr_tog, "top-attr");
2468 i_e.parentNode.insertBefore(attr_tog, i_e);
2469 itemAttributesFunc(i_e);
2472 // To avoid checking on "rustdoc-line-numbers" value on every loop...
2473 var lineNumbersFunc = function() {};
2474 if (getCurrentValue("rustdoc-line-numbers") === "true") {
2475 lineNumbersFunc = function(x) {
2476 var count = x.textContent.split("\n").length;
2478 for (var i = 0; i < count; ++i) {
2481 var node = document.createElement("pre");
2482 addClass(node, "line-number");
2483 node.innerHTML = elems.join("\n");
2484 x.parentNode.insertBefore(node, x);
2487 onEachLazy(document.getElementsByClassName("rust-example-rendered"), function(e) {
2488 if (hasClass(e, "compile_fail")) {
2489 e.addEventListener("mouseover", function(event) {
2490 this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00";
2492 e.addEventListener("mouseout", function(event) {
2493 this.parentElement.previousElementSibling.childNodes[0].style.color = "";
2495 } else if (hasClass(e, "ignore")) {
2496 e.addEventListener("mouseover", function(event) {
2497 this.parentElement.previousElementSibling.childNodes[0].style.color = "#ff9200";
2499 e.addEventListener("mouseout", function(event) {
2500 this.parentElement.previousElementSibling.childNodes[0].style.color = "";
2506 // In the search display, allows to switch between tabs.
2507 function printTab(nb) {
2508 if (nb === 0 || nb === 1 || nb === 2) {
2512 onEachLazy(document.getElementById("titles").childNodes, function(elem) {
2513 if (nb_copy === 0) {
2514 addClass(elem, "selected");
2516 removeClass(elem, "selected");
2520 onEachLazy(document.getElementById("results").childNodes, function(elem) {
2522 elem.style.display = "";
2524 elem.style.display = "none";
2530 function putBackSearch(search_input) {
2531 var search = getSearchElement();
2532 if (search_input.value !== "" && hasClass(search, "hidden")) {
2533 showSearchResults(search);
2534 if (browserSupportsHistoryApi()) {
2535 history.replaceState(search_input.value,
2537 "?search=" + encodeURIComponent(search_input.value));
2543 search_input.onfocus = function() {
2544 putBackSearch(this);
2548 var params = getQueryStringParams();
2549 if (params && params.search) {
2550 var search = getSearchElement();
2551 search.innerHTML = "<h3 style=\"text-align: center;\">Loading search results...</h3>";
2552 showSearchResults(search);
2555 var sidebar_menu = document.getElementsByClassName("sidebar-menu")[0];
2557 sidebar_menu.onclick = function() {
2558 var sidebar = document.getElementsByClassName("sidebar")[0];
2559 if (hasClass(sidebar, "mobile") === true) {
2567 window.onresize = function() {
2571 autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
2573 if (window.location.hash && window.location.hash.length > 0) {
2574 expandSection(window.location.hash.replace(/^#/, ""));
2578 onEachLazy(main.getElementsByClassName("loading-content"), function(e) {
2581 onEachLazy(main.childNodes, function(e) {
2582 // Unhide the actual content once loading is complete. Headers get
2583 // flex treatment for their horizontal layout, divs get block treatment
2584 // for vertical layout (column-oriented flex layout for divs caused
2585 // errors in mobile browsers).
2586 if (e.tagName === "H2" || e.tagName === "H3") {
2587 var nextTagName = e.nextElementSibling.tagName;
2588 if (nextTagName == "H2" || nextTagName == "H3") {
2589 e.nextElementSibling.style.display = "flex";
2591 e.nextElementSibling.style.display = "block";
2597 function addSearchOptions(crates) {
2598 var elem = document.getElementById("crate-search");
2603 var crates_text = [];
2604 if (Object.keys(crates).length > 1) {
2605 for (var crate in crates) {
2606 if (crates.hasOwnProperty(crate)) {
2607 crates_text.push(crate);
2611 crates_text.sort(function(a, b) {
2612 var lower_a = a.toLowerCase();
2613 var lower_b = b.toLowerCase();
2615 if (lower_a < lower_b) {
2617 } else if (lower_a > lower_b) {
2622 var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
2623 for (var i = 0; i < crates_text.length; ++i) {
2624 var option = document.createElement("option");
2625 option.value = crates_text[i];
2626 option.innerText = crates_text[i];
2627 elem.appendChild(option);
2628 // Set the crate filter from saved storage, if the current page has the saved crate
2631 // If not, ignore the crate filter -- we want to support filtering for crates on sites
2632 // like doc.rust-lang.org where the crates may differ from page to page while on the
2634 if (crates_text[i] === savedCrate) {
2635 elem.value = savedCrate;
2640 search_input.removeAttribute('disabled');
2644 window.addSearchOptions = addSearchOptions;
2646 function buildHelperPopup() {
2647 var popup = document.createElement("aside");
2648 addClass(popup, "hidden");
2651 var container = document.createElement("div");
2653 ["?", "Show this help dialog"],
2654 ["S", "Focus the search field"],
2655 ["↑", "Move up in search results"],
2656 ["↓", "Move down in search results"],
2657 ["↹", "Switch tab"],
2658 ["⏎", "Go to active search result"],
2659 ["+", "Expand all sections"],
2660 ["-", "Collapse all sections"],
2661 ].map(x => "<dt><kbd>" + x[0] + "</kbd></dt><dd>" + x[1] + "</dd>").join("");
2662 var div_shortcuts = document.createElement("div");
2663 addClass(div_shortcuts, "shortcuts");
2664 div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
2667 "Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
2668 restrict the search to a given type.",
2669 "Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
2670 <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \
2671 and <code>const</code>.",
2672 "Search functions by type signature (e.g., <code>vec -> usize</code> or \
2673 <code>* -> vec</code>)",
2674 "Search multiple things at once by splitting your query with comma (e.g., \
2675 <code>str,u8</code> or <code>String,struct:Vec,test</code>)",
2676 "You can look for items with an exact name by putting double quotes around \
2677 your request: <code>\"string\"</code>",
2678 "Look for items inside another one by searching for a path: <code>vec::Vec</code>",
2679 ].map(x => "<p>" + x + "</p>").join("");
2680 var div_infos = document.createElement("div");
2681 addClass(div_infos, "infos");
2682 div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;
2684 container.appendChild(div_shortcuts);
2685 container.appendChild(div_infos);
2687 popup.appendChild(container);
2688 insertAfter(popup, getSearchElement());
2692 window.onhashchange = onHashChange;
2697 // Sets the focus on the search bar at the top of the page
2698 function focusSearchBar() {
2699 getSearchInput().focus();
2702 // Removes the focus from the search bar
2703 function defocusSearchBar() {
2704 getSearchInput().blur();