2 /* global ALIASES, currentCrate, rootPath */
4 // Local js definitions:
5 /* global addClass, getCurrentValue, hasClass */
6 /* global onEachLazy, hasOwnProperty, 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");
50 // Sets the focus on the search bar at the top of the page
51 function focusSearchBar() {
52 getSearchInput().focus();
55 // Removes the focus from the search bar
56 function defocusSearchBar() {
57 getSearchInput().blur();
63 // This mapping table should match the discriminants of
64 // `rustdoc::html::item_type::ItemType` type in Rust.
65 var itemTypes = ["mod",
92 var disableShortcuts = getCurrentValue("rustdoc-disable-shortcuts") === "true";
93 var search_input = getSearchInput();
94 var searchTimeout = null;
96 // On the search screen, so you remain on the last tab you opened.
99 // 1 for "In Parameters"
100 // 2 for "In Return Types"
103 var mouseMovedAfterSearch = true;
105 var titleBeforeSearch = document.title;
107 function clearInputTimeout() {
108 if (searchTimeout !== null) {
109 clearTimeout(searchTimeout);
110 searchTimeout = null;
114 function getPageId() {
115 if (window.location.hash) {
116 var tmp = window.location.hash.replace(/^#/, "");
117 if (tmp.length > 0) {
124 function showSidebar() {
125 var elems = document.getElementsByClassName("sidebar-elems")[0];
127 addClass(elems, "show-it");
129 var sidebar = document.getElementsByClassName("sidebar")[0];
131 addClass(sidebar, "mobile");
132 var filler = document.getElementById("sidebar-filler");
134 var div = document.createElement("div");
135 div.id = "sidebar-filler";
136 sidebar.appendChild(div);
139 var themePickers = document.getElementsByClassName("theme-picker");
140 if (themePickers && themePickers.length > 0) {
141 themePickers[0].style.display = "none";
145 function hideSidebar() {
146 var elems = document.getElementsByClassName("sidebar-elems")[0];
148 removeClass(elems, "show-it");
150 var sidebar = document.getElementsByClassName("sidebar")[0];
151 removeClass(sidebar, "mobile");
152 var filler = document.getElementById("sidebar-filler");
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;
163 function showSearchResults(search) {
164 if (search === null || typeof search === 'undefined') {
165 search = getSearchElement();
167 addClass(main, "hidden");
168 removeClass(search, "hidden");
169 mouseMovedAfterSearch = false;
172 function hideSearchResults(search) {
173 if (search === null || typeof search === 'undefined') {
174 search = getSearchElement();
176 addClass(search, "hidden");
177 removeClass(main, "hidden");
180 // used for special search precedence
181 var TY_PRIMITIVE = itemTypes.indexOf("primitive");
182 var TY_KEYWORD = itemTypes.indexOf("keyword");
184 function getQueryStringParams() {
186 window.location.search.substring(1).split("&").
188 var pair = s.split("=");
189 params[decodeURIComponent(pair[0])] =
190 typeof pair[1] === "undefined" ? null : decodeURIComponent(pair[1]);
195 function browserSupportsHistoryApi() {
196 return window.history && typeof window.history.pushState === "function";
199 function isHidden(elem) {
200 return elem.offsetHeight === 0;
203 var main = document.getElementById("main");
206 function handleHashes(ev) {
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
212 hideSearchResults(search);
213 var hash = ev.newURL.slice(ev.newURL.indexOf("#") + 1);
214 if (browserSupportsHistoryApi()) {
215 history.replaceState(hash, "", "?search=#" + hash);
217 elem = document.getElementById(hash);
219 elem.scrollIntoView();
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) {
228 elem = document.getElementById(savedHash.slice(1)); // we remove the '#'
229 if (!elem || !isHidden(elem)) {
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.
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();
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.
257 match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
262 var from = parseInt(match[1], 10);
264 if (typeof match[2] !== "undefined") {
265 to = parseInt(match[2], 10);
272 var elem = document.getElementById(from);
277 var x = document.getElementById(from);
282 onEachLazy(document.getElementsByClassName("line-numbers"), function(e) {
283 onEachLazy(e.getElementsByTagName("span"), function(i_e) {
284 removeClass(i_e, "line-highlighted");
287 for (var i = from; i <= to; ++i) {
288 elem = document.getElementById(i);
292 addClass(elem, "line-highlighted");
296 function onHashChange(ev) {
297 // If we're in mobile mode, we should hide the sidebar in any case.
299 var match = window.location.hash.match(/^#?(\d+)(?:-(\d+))?$/);
301 return highlightSourceLines(match, ev);
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
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");
324 // Gets the human-readable string for the virtual-key code of the
325 // given KeyboardEvent, ev.
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.
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") {
339 var c = ev.charCode || ev.keyCode;
343 return String.fromCharCode(c);
346 function getHelpElement() {
347 return document.getElementById("help");
350 function displayHelp(display, ev, help) {
351 help = help ? help : getHelpElement();
352 if (display === true) {
353 if (hasClass(help, "hidden")) {
355 removeClass(help, "hidden");
356 addClass(document.body, "blur");
358 } else if (hasClass(help, "hidden") === false) {
360 addClass(help, "hidden");
361 removeClass(document.body, "blur");
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) {
373 hideSearchResults(search);
374 document.title = titleBeforeSearch;
379 function handleShortcut(ev) {
380 // Don't interfere with browser shortcuts
381 if (ev.ctrlKey || ev.altKey || ev.metaKey || disableShortcuts === true) {
385 if (document.activeElement.tagName === "INPUT") {
386 switch (getVirtualKey(ev)) {
392 switch (getVirtualKey(ev)) {
399 displayHelp(false, ev);
411 displayHelp(true, ev);
417 function findParentElement(elem, tagName) {
419 if (elem && elem.tagName === tagName) {
422 elem = elem.parentNode;
427 document.addEventListener("keypress", handleShortcut);
428 document.addEventListener("keydown", handleShortcut);
430 function resetMouseMoved(ev) {
431 mouseMovedAfterSearch = true;
434 document.addEventListener("mousemove", resetMouseMoved);
436 var handleSourceHighlight = (function() {
437 var prev_line_id = 0;
439 var set_fragment = function(name) {
440 var x = window.scrollX,
442 if (browserSupportsHistoryApi()) {
443 history.replaceState(null, null, "#" + name);
444 highlightSourceLines();
446 location.replace("#" + name);
448 // Prevent jumps when selecting one or many lines
449 window.scrollTo(x, y);
452 return function(ev) {
453 var cur_line_id = parseInt(ev.target.id, 10);
456 if (ev.shiftKey && prev_line_id) {
457 // Swap selection if needed
458 if (prev_line_id > cur_line_id) {
459 var tmp = prev_line_id;
460 prev_line_id = cur_line_id;
464 set_fragment(prev_line_id + "-" + cur_line_id);
466 prev_line_id = cur_line_id;
468 set_fragment(cur_line_id);
473 document.addEventListener("click", function(ev) {
474 if (hasClass(ev.target, "help-button")) {
475 displayHelp(true, ev);
476 } else if (hasClass(ev.target, "collapse-toggle")) {
477 collapseDocs(ev.target, "toggle");
478 } else if (hasClass(ev.target.parentNode, "collapse-toggle")) {
479 collapseDocs(ev.target.parentNode, "toggle");
480 } else if (ev.target.tagName === "SPAN" && hasClass(ev.target.parentNode, "line-numbers")) {
481 handleSourceHighlight(ev);
482 } else if (hasClass(getHelpElement(), "hidden") === false) {
483 var help = getHelpElement();
484 var is_inside_help_popup = ev.target !== help && help.contains(ev.target);
485 if (is_inside_help_popup === false) {
486 addClass(help, "hidden");
487 removeClass(document.body, "blur");
490 // Making a collapsed element visible on onhashchange seems
492 var a = findParentElement(ev.target, "A");
494 expandSection(a.hash.replace(/^#/, ""));
500 var x = document.getElementsByClassName("version-selector");
502 x[0].onchange = function() {
504 url = document.location.href,
506 len = rootPath.match(/\.\.\//g).length + 1;
508 for (i = 0; i < len; ++i) {
509 match = url.match(/\/[^\/]*$/);
511 stripped = match[0] + stripped;
513 url = url.substring(0, url.length - match[0].length);
516 var selectedVersion = document.getElementsByClassName("version-selector")[0].value;
517 url += "/" + selectedVersion + stripped;
519 document.location.href = url;
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
531 var levenshtein_row2 = [];
532 function levenshtein(s1, s2) {
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) {
542 while (i2 < s2_len) {
543 c2 = s2.charCodeAt(i2);
547 for (i1 = 0; i1 < s1_len; ++i1) {
548 c = a + (s1.charCodeAt(i1) !== c2 ? 1 : 0);
550 b = b < a ? (b < c ? b + 1 : c) : (a < c ? a + 1 : c);
556 return s1_len + s2_len;
559 window.initSearch = function(rawSearchIndex) {
560 var MAX_LEV_DISTANCE = 3;
561 var MAX_RESULTS = 200;
562 var GENERICS_DATA = 1;
566 var NO_TYPE_FILTER = -1;
567 var currentResults, index, searchIndex;
569 var params = getQueryStringParams();
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 || "";
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
584 * @param {[type]} filterCrates [Crate to search in if defined]
585 * @return {[type]} [A search index of results]
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) {
595 return NO_TYPE_FILTER;
598 var valLower = query.query.toLowerCase(),
600 typeFilter = itemTypeFromName(query.type),
601 results = {}, results_in_args = {}, results_returned = {},
602 split = valLower.split("::");
604 var length = split.length;
605 for (var z = 0; z < length; ++z) {
606 if (split[z] === "") {
612 function transformResults(results, isType) {
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;
627 if (out.length >= MAX_RESULTS) {
636 function sortResults(results, isType) {
638 for (var entry in results) {
639 if (hasOwnProperty(results, entry)) {
640 ar.push(results[entry]);
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] || {};
650 // if there are no results then return to default and fail
651 if (results.length === 0) {
655 results.sort(function(aaa, bbb) {
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; }
663 // Sort by non levenshtein results and then levenshtein results by the distance
664 // (less changes required to match means higher rankings)
667 if (a !== b) { return a - b; }
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; }
674 // sort by item name length (longer goes later)
677 if (a !== b) { return a - b; }
679 // sort by item name (lexicographically larger goes later)
682 if (a !== b) { return (a > b ? +1 : -1); }
684 // sort by index of keyword in item name (no literal occurrence goes later)
687 if (a !== b) { return a - b; }
688 // (later literal occurrence, if any, goes later)
691 if (a !== b) { return a - b; }
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)) {
698 if ((bbb.item.ty === TY_PRIMITIVE && aaa.item.ty !== TY_PRIMITIVE) ||
699 (bbb.item.ty === TY_KEYWORD && aaa.item.ty !== TY_KEYWORD)) {
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; }
708 // sort by type (later occurrence in `itemTypes` goes later)
711 if (a !== b) { return a - b; }
713 // sort by path (lexicographically larger goes later)
716 if (a !== b) { return (a > b ? +1 : -1); }
722 var length = results.length;
723 for (i = 0; i < length; ++i) {
724 var result = results[i];
726 // this validation does not make sense when searching by types
727 if (result.dontValidate) {
730 var name = result.item.name.toLowerCase(),
731 path = result.item.path.toLowerCase(),
732 parent = result.item.parent;
734 if (isType !== true &&
735 validateResult(name, path, split, parent) === false)
740 return transformResults(results);
743 function extractGenerics(val) {
744 val = val.toLowerCase();
745 if (val.indexOf("<") !== -1) {
746 var values = val.substring(val.indexOf("<") + 1, val.lastIndexOf(">"));
748 name: val.substring(0, val.indexOf("<")),
749 generics: values.split(/\s*,\s*/),
758 function getObjectFromId(id) {
759 if (typeof id === "number") {
760 return searchIndex[id];
765 function checkGenerics(obj, val) {
766 // The names match, but we need to be sure that all generics kinda
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);
775 // We need to find the type that matches the most to remove it in order
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,
785 if (tmp_lev < lev.lev) {
790 if (lev.pos !== -1) {
791 elems.splice(lev.pos, 1);
792 lev_distance = Math.min(lev.lev, lev_distance);
796 return MAX_LEV_DISTANCE + 1;
799 return Math.ceil(total / done);
802 return MAX_LEV_DISTANCE + 1;
805 // Check for type name and type generics (if any).
806 function checkType(obj, val, literalSearch) {
807 var lev_distance = MAX_LEV_DISTANCE + 1;
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);
817 for (var y = 0; allFound === true && y < val.generics.length; ++y) {
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;
823 if (allFound === true) {
824 elems.splice(x - 1, 1);
827 if (allFound === true) {
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) {
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) {
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),
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;
878 function findArg(obj, val, literalSearch, typeFilter) {
879 var lev_distance = MAX_LEV_DISTANCE + 1;
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) {
888 tmp = checkType(tmp, val, literalSearch);
889 if (literalSearch === true) {
895 lev_distance = Math.min(tmp, lev_distance);
896 if (lev_distance === 0) {
901 return literalSearch === true ? false : lev_distance;
904 function checkReturned(obj, val, literalSearch, typeFilter) {
905 var lev_distance = MAX_LEV_DISTANCE + 1;
907 if (obj && obj.type && obj.type.length > OUTPUT_DATA) {
908 var ret = obj.type[OUTPUT_DATA];
909 if (typeof ret[0] === "string") {
912 for (var x = 0; x < ret.length; ++x) {
914 if (typePassesFilter(typeFilter, tmp[1]) === false) {
917 tmp = checkType(tmp, val, literalSearch);
918 if (literalSearch === true) {
924 lev_distance = Math.min(tmp, lev_distance);
925 if (lev_distance === 0) {
930 return literalSearch === true ? false : lev_distance;
933 function checkPath(contains, lastElem, ty) {
934 if (contains.length === 0) {
937 var ret_lev = MAX_LEV_DISTANCE + 1;
938 var path = ty.path.split("::");
940 if (ty.parent && ty.parent.name) {
941 path.push(ty.parent.name.toLowerCase());
944 var length = path.length;
945 var clength = contains.length;
946 if (clength > length) {
947 return MAX_LEV_DISTANCE + 1;
949 for (var i = 0; i < length; ++i) {
950 if (i + clength > length) {
955 for (var x = 0; x < clength; ++x) {
956 var lev = levenshtein(path[i + x], contains[x]);
957 if (lev > MAX_LEV_DISTANCE) {
963 if (aborted === false) {
964 ret_lev = Math.min(ret_lev, Math.round(lev_total / clength));
970 function typePassesFilter(filter, type) {
972 if (filter <= NO_TYPE_FILTER) return true;
975 if (filter === type) return true;
977 // Match related items
978 var name = itemTypes[type];
979 switch (itemTypes[filter]) {
981 return name === "associatedconstant";
983 return name === "method" || name === "tymethod";
985 return name === "primitive" || name === "associatedtype";
987 return name === "traitalias";
994 function generateId(ty) {
995 if (ty.parent && ty.parent.name) {
996 return itemTypes[ty.ty] + ty.path + ty.parent.name + ty.name;
998 return itemTypes[ty.ty] + ty.path + ty.name;
1001 function createAliasFromItem(item) {
1008 parent: item.parent,
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.
1018 var crateAliases = [];
1020 if (filterCrates !== undefined) {
1021 if (ALIASES[filterCrates] && ALIASES[filterCrates][query.search]) {
1022 for (i = 0; i < ALIASES[filterCrates][query.search].length; ++i) {
1024 createAliasFromItem(
1025 searchIndex[ALIASES[filterCrates][query.search][i]]));
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) {
1034 createAliasFromItem(
1035 searchIndex[ALIASES[crate][query.search][i]]));
1041 var sortFunc = function(aaa, bbb) {
1042 if (aaa.path < bbb.path) {
1044 } else if (aaa.path === bbb.path) {
1049 crateAliases.sort(sortFunc);
1050 aliases.sort(sortFunc);
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];
1059 ret.others.unshift(alias);
1060 if (ret.others.length > MAX_RESULTS) {
1064 onEach(aliases, pushFunc);
1065 onEach(crateAliases, pushFunc);
1068 // quoted values mean literal search
1069 var nSearchWords = searchWords.length;
1075 if ((val.charAt(0) === "\"" || val.charAt(0) === "'") &&
1076 val.charAt(val.length - 1) === val.charAt(0))
1078 val = extractGenerics(val.substr(1, val.length - 2));
1079 for (i = 0; i < nSearchWords; ++i) {
1080 if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) {
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);
1088 if (searchWords[i] === val.name
1089 && typePassesFilter(typeFilter, searchIndex[i].ty)
1090 && results[fullId] === undefined) {
1097 if (in_args === true && results_in_args[fullId] === undefined) {
1098 results_in_args[fullId] = {
1104 if (returned === true && results_returned[fullId] === undefined) {
1105 results_returned[fullId] = {
1112 query.inputs = [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]);
1125 var output = extractGenerics(parts[1]);
1127 for (i = 0; i < nSearchWords; ++i) {
1128 if (filterCrates !== undefined && searchIndex[i].crate !== filterCrates) {
1131 var type = searchIndex[i].type;
1132 ty = searchIndex[i];
1136 fullId = generateId(ty);
1138 returned = checkReturned(ty, output, true, NO_TYPE_FILTER);
1139 if (output.name === "*" || returned === true) {
1141 var is_module = false;
1143 if (input === "*") {
1146 var allFound = true;
1147 for (var it = 0; allFound === true && it < inputs.length; it++) {
1148 allFound = checkType(type, inputs[it], true);
1152 if (in_args === true) {
1153 results_in_args[fullId] = {
1159 if (returned === true) {
1160 results_returned[fullId] = {
1166 if (is_module === true) {
1175 query.inputs = inputs.map(function(input) {
1178 query.output = output.name;
1180 query.inputs = [val];
1183 // gather matching search results up to a certain maximum
1184 val = val.replace(/\_/g, "");
1186 var valGenerics = extractGenerics(val);
1188 var paths = valLower.split("::");
1190 for (j = 0; j < paths.length; ++j) {
1191 if (paths[j] === "") {
1196 val = paths[paths.length - 1];
1197 var contains = paths.slice(0, paths.length > 1 ? paths.length - 1 : 1);
1200 for (j = 0; j < nSearchWords; ++j) {
1201 ty = searchIndex[j];
1202 if (!ty || (filterCrates !== undefined && ty.crate !== filterCrates)) {
1206 if (paths.length > 1) {
1207 lev = checkPath(contains, paths[paths.length - 1], ty);
1208 if (lev > MAX_LEV_DISTANCE) {
1210 } else if (lev > 0) {
1215 returned = MAX_LEV_DISTANCE + 1;
1216 in_args = MAX_LEV_DISTANCE + 1;
1218 // we want lev results to go lower than others
1219 lev = MAX_LEV_DISTANCE + 1;
1220 fullId = generateId(ty);
1222 if (searchWords[j].indexOf(split[i]) > -1 ||
1223 searchWords[j].indexOf(val) > -1 ||
1224 searchWords[j].replace(/_/g, "").indexOf(val) > -1)
1226 // filter type: ... queries
1227 if (typePassesFilter(typeFilter, ty.ty) && results[fullId] === undefined) {
1228 index = searchWords[j].replace(/_/g, "").indexOf(val);
1231 if ((lev = levenshtein(searchWords[j], val)) <= MAX_LEV_DISTANCE) {
1232 if (typePassesFilter(typeFilter, ty.ty) === false) {
1233 lev = MAX_LEV_DISTANCE + 1;
1238 in_args = findArg(ty, valGenerics, false, typeFilter);
1239 returned = checkReturned(ty, valGenerics, false, typeFilter);
1242 if (lev > 0 && val.length > 3 && searchWords[j].indexOf(val) > -1) {
1243 if (val.length < 6) {
1249 if (in_args <= MAX_LEV_DISTANCE) {
1250 if (results_in_args[fullId] === undefined) {
1251 results_in_args[fullId] = {
1257 results_in_args[fullId].lev =
1258 Math.min(results_in_args[fullId].lev, in_args);
1260 if (returned <= MAX_LEV_DISTANCE) {
1261 if (results_returned[fullId] === undefined) {
1262 results_returned[fullId] = {
1268 results_returned[fullId].lev =
1269 Math.min(results_returned[fullId].lev, returned);
1271 if (index !== -1 || lev <= MAX_LEV_DISTANCE) {
1272 if (index !== -1 && paths.length < 2) {
1275 if (results[fullId] === undefined) {
1282 results[fullId].lev = Math.min(results[fullId].lev, lev);
1288 "in_args": sortResults(results_in_args, true),
1289 "returned": sortResults(results_returned, true),
1290 "others": sortResults(results),
1292 handleAliases(ret, query, filterCrates);
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
1302 * This could be written functionally, but I wanted to minimise
1303 * functions on stack.
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]
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
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)) {
1330 function getQuery(raw) {
1331 var matches, type, query;
1334 matches = query.match(/^(fn|mod|struct|enum|trait|type|const|macro)\s*:\s*/i);
1336 type = matches[1].replace(/^const$/, "constant");
1337 query = query.substring(matches[0].length);
1348 function initSearchNav() {
1351 var click_func = function(e) {
1353 // to retrieve the real "owner" of the event.
1354 while (el.tagName !== "TR") {
1357 var dst = e.target.getElementsByTagName("a");
1358 if (dst.length < 1) {
1362 if (window.location.pathname === dst.pathname) {
1363 hideSearchResults();
1364 document.location.href = dst.href;
1367 var mouseover_func = function(e) {
1368 if (mouseMovedAfterSearch) {
1370 // to retrieve the real "owner" of the event.
1371 while (el.tagName !== "TR") {
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");
1381 addClass(el, "highlighted");
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;
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.
1398 onEachLazy(document.getElementById("results").childNodes, function(e) {
1399 onEachLazy(e.getElementsByClassName("highlighted"), function(e) {
1400 actives[current].push(e);
1405 if (e.which === 38) { // up
1406 if (!actives[currentTab].length ||
1407 !actives[currentTab][0].previousElementSibling) {
1411 addClass(actives[currentTab][0].previousElementSibling, "highlighted");
1412 removeClass(actives[currentTab][0], "highlighted");
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");
1423 } else if (actives[currentTab][0].nextElementSibling) {
1424 addClass(actives[currentTab][0].nextElementSibling, "highlighted");
1425 removeClass(actives[currentTab][0], "highlighted");
1428 } else if (e.which === 13) { // return
1429 if (actives[currentTab].length) {
1430 document.location.href =
1431 actives[currentTab][0].getElementsByTagName("a")[0].href;
1433 } else if (e.which === 9) { // tab
1435 printTab(currentTab > 0 ? currentTab - 1 : 2);
1437 printTab(currentTab > 1 ? 0 : currentTab + 1);
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");
1448 function buildHrefAndPath(item) {
1451 var type = itemTypes[item.ty];
1452 var name = item.name;
1453 var path = item.path;
1455 if (type === "mod") {
1456 displayPath = path + "::";
1457 href = rootPath + path.replace(/::/g, "/") + "/" +
1458 name + "/index.html";
1459 } else if (type === "primitive" || type === "keyword") {
1461 href = rootPath + path.replace(/::/g, "/") +
1462 "/" + type + "." + name + ".html";
1463 } else if (type === "externcrate") {
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;
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;
1484 pageName = enumName;
1486 displayPath = path + "::" + myparent.name + "::";
1488 href = rootPath + path.replace(/::/g, "/") +
1493 displayPath = item.path + "::";
1494 href = rootPath + item.path.replace(/::/g, "/") +
1495 "/" + type + "." + name + ".html";
1497 return [displayPath, href];
1500 function escape(content) {
1501 var h1 = document.createElement("h1");
1502 h1.textContent = content;
1503 return h1.innerHTML;
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);
1514 function addTab(array, query, display) {
1515 var extraStyle = "";
1516 if (display === false) {
1517 extraStyle = " style=\"display: none;\"";
1521 var duplicates = {};
1523 if (array.length > 0) {
1524 output = "<table class=\"search-results\"" + extraStyle + ">";
1526 array.forEach(function(item) {
1530 type = itemTypes[item.ty];
1532 if (item.is_alias !== true) {
1533 if (duplicates[item.fullPath]) {
1536 duplicates[item.fullPath] = true;
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> - see </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 " </span></a></td></tr>";
1551 output += "</table>";
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>";
1567 return [output, length];
1570 function makeTabHeader(tabNb, text, nbElems) {
1571 if (currentTab === tabNb) {
1572 return "<div class=\"selected\">" + text +
1573 " <div class=\"count\">(" + nbElems + ")</div></div>";
1575 return "<div>" + text + " <div class=\"count\">(" + nbElems + ")</div></div>";
1578 function showResults(results) {
1579 var search = getSearchElement();
1580 if (results.others.length === 1
1581 && getCurrentValue("rustdoc-go-to-only-result") === "true"
1582 // By default, the search DOM element is "empty" (meaning it has no children not
1583 // text content). Once a search has been run, it won't be empty, even if you press
1584 // ESC or empty the search input (which also "cancels" the search).
1585 && (!search.firstChild || search.firstChild.innerText !== getSearchLoadingText()))
1587 var elem = document.createElement("a");
1588 elem.href = results.others[0].href;
1589 elem.style.display = "none";
1590 // For firefox, we need the element to be in the DOM so it can be clicked.
1591 document.body.appendChild(elem);
1595 var query = getQuery(search_input.value);
1597 currentResults = query.id;
1599 var ret_others = addTab(results.others, query);
1600 var ret_in_args = addTab(results.in_args, query, false);
1601 var ret_returned = addTab(results.returned, query, false);
1603 var output = "<h1>Results for " + escape(query.query) +
1604 (query.type ? " (type: " + escape(query.type) + ")" : "") + "</h1>" +
1605 "<div id=\"titles\">" +
1606 makeTabHeader(0, "In Names", ret_others[1]) +
1607 makeTabHeader(1, "In Parameters", ret_in_args[1]) +
1608 makeTabHeader(2, "In Return Types", ret_returned[1]) +
1609 "</div><div id=\"results\">" +
1610 ret_others[0] + ret_in_args[0] + ret_returned[0] + "</div>";
1612 search.innerHTML = output;
1613 showSearchResults(search);
1614 var tds = search.getElementsByTagName("td");
1616 if (tds.length > 0) {
1617 td_width = tds[0].offsetWidth;
1619 var width = search.offsetWidth - 40 - td_width;
1620 onEachLazy(search.getElementsByClassName("desc"), function(e) {
1621 e.style.width = width + "px";
1624 var elems = document.getElementById("titles").childNodes;
1625 elems[0].onclick = function() { printTab(0); };
1626 elems[1].onclick = function() { printTab(1); };
1627 elems[2].onclick = function() { printTab(2); };
1628 printTab(currentTab);
1631 function execSearch(query, searchWords, filterCrates) {
1632 function getSmallest(arrays, positions, notDuplicates) {
1635 for (var it = 0; it < positions.length; ++it) {
1636 if (arrays[it].length > positions[it] &&
1637 (start === null || start > arrays[it][positions[it]].lev) &&
1638 !notDuplicates[arrays[it][positions[it]].fullPath]) {
1639 start = arrays[it][positions[it]].lev;
1645 function mergeArrays(arrays) {
1648 var notDuplicates = {};
1650 for (var x = 0; x < arrays.length; ++x) {
1653 while (ret.length < MAX_RESULTS) {
1654 var smallest = getSmallest(arrays, positions, notDuplicates);
1656 if (smallest === null) {
1659 for (x = 0; x < arrays.length && ret.length < MAX_RESULTS; ++x) {
1660 if (arrays[x].length > positions[x] &&
1661 arrays[x][positions[x]].lev === smallest &&
1662 !notDuplicates[arrays[x][positions[x]].fullPath]) {
1663 ret.push(arrays[x][positions[x]]);
1664 notDuplicates[arrays[x][positions[x]].fullPath] = true;
1672 var queries = query.raw.split(",");
1679 for (var i = 0; i < queries.length; ++i) {
1680 query = queries[i].trim();
1681 if (query.length !== 0) {
1682 var tmp = execQuery(getQuery(query), searchWords, filterCrates);
1684 results.in_args.push(tmp.in_args);
1685 results.returned.push(tmp.returned);
1686 results.others.push(tmp.others);
1689 if (queries.length > 1) {
1691 "in_args": mergeArrays(results.in_args),
1692 "returned": mergeArrays(results.returned),
1693 "others": mergeArrays(results.others),
1697 "in_args": results.in_args[0],
1698 "returned": results.returned[0],
1699 "others": results.others[0],
1703 function getFilterCrates() {
1704 var elem = document.getElementById("crate-search");
1706 if (elem && elem.value !== "All crates" && hasOwnProperty(rawSearchIndex, elem.value)) {
1712 function search(e, forced) {
1713 var params = getQueryStringParams();
1714 var query = getQuery(search_input.value.trim());
1720 if (query.query.length === 0) {
1723 if (forced !== true && query.id === currentResults) {
1724 if (query.query.length > 0) {
1725 putBackSearch(search_input);
1730 // Update document title to maintain a meaningful browser history
1731 document.title = "Results for " + query.query + " - Rust";
1733 // Because searching is incremental by character, only the most
1734 // recent search query is added to the browser history.
1735 if (browserSupportsHistoryApi()) {
1736 if (!history.state && !params.search) {
1737 history.pushState(query, "", "?search=" + encodeURIComponent(query.raw));
1739 history.replaceState(query, "", "?search=" + encodeURIComponent(query.raw));
1743 var filterCrates = getFilterCrates();
1744 showResults(execSearch(query, index, filterCrates));
1747 function buildIndex(rawSearchIndex) {
1749 var searchWords = [];
1751 var currentIndex = 0;
1753 for (var crate in rawSearchIndex) {
1754 if (!hasOwnProperty(rawSearchIndex, crate)) { continue; }
1758 searchWords.push(crate);
1761 ty: 1, // == ExternCrate
1764 desc: rawSearchIndex[crate].doc,
1769 // an array of [(Number) item type,
1771 // (String) full path or empty string for previous path,
1772 // (String) description,
1773 // (Number | null) the parent path index to `paths`]
1774 // (Object | null) the type of the function (if any)
1775 var items = rawSearchIndex[crate].i;
1776 // an array of [(Number) item type,
1778 var paths = rawSearchIndex[crate].p;
1779 // a array of [(String) alias name
1780 // [Number] index to items]
1781 var aliases = rawSearchIndex[crate].a;
1783 // convert `rawPaths` entries into object form
1784 var len = paths.length;
1785 for (i = 0; i < len; ++i) {
1786 paths[i] = {ty: paths[i][0], name: paths[i][1]};
1789 // convert `items` into an object form, and construct word indices.
1791 // before any analysis is performed lets gather the search terms to
1792 // search against apart from the rest of the data. This is a quick
1793 // operation that is cached for the life of the page state so that
1794 // all other search operations have access to this cached data for
1795 // faster analysis operations
1798 for (i = 0; i < len; ++i) {
1799 var rawRow = items[i];
1801 rawRow[2] = lastPath;
1809 parent: paths[rawRow[4]],
1812 searchIndex.push(row);
1813 if (typeof row.name === "string") {
1814 var word = row.name.toLowerCase();
1815 searchWords.push(word);
1817 searchWords.push("");
1819 lastPath = row.path;
1824 ALIASES[crate] = {};
1825 var j, local_aliases;
1826 for (var alias_name in aliases) {
1827 if (!aliases.hasOwnProperty(alias_name)) { continue; }
1829 if (!ALIASES[crate].hasOwnProperty(alias_name)) {
1830 ALIASES[crate][alias_name] = [];
1832 local_aliases = aliases[alias_name];
1833 for (j = 0; j < local_aliases.length; ++j) {
1834 ALIASES[crate][alias_name].push(local_aliases[j] + currentIndex);
1838 currentIndex += crateSize;
1843 function startSearch() {
1844 var callback = function() {
1845 clearInputTimeout();
1846 if (search_input.value.length === 0) {
1847 if (browserSupportsHistoryApi()) {
1848 history.replaceState("", window.currentCrate + " - Rust", "?search=");
1850 hideSearchResults();
1852 searchTimeout = setTimeout(search, 500);
1855 search_input.onkeyup = callback;
1856 search_input.oninput = callback;
1857 document.getElementsByClassName("search-form")[0].onsubmit = function(e) {
1859 clearInputTimeout();
1862 search_input.onchange = function(e) {
1863 if (e.target !== document.activeElement) {
1864 // To prevent doing anything when it's from a blur event.
1867 // Do NOT e.preventDefault() here. It will prevent pasting.
1868 clearInputTimeout();
1869 // zero-timeout necessary here because at the time of event handler execution the
1870 // pasted content is not in the input field yet. Shouldn’t make any difference for
1872 setTimeout(search, 0);
1874 search_input.onpaste = search_input.onchange;
1876 var selectCrate = document.getElementById("crate-search");
1878 selectCrate.onchange = function() {
1879 updateLocalStorage("rustdoc-saved-filter-crate", selectCrate.value);
1880 search(undefined, true);
1884 // Push and pop states are used to add search results to the browser
1886 if (browserSupportsHistoryApi()) {
1887 // Store the previous <title> so we can revert back to it later.
1888 var previousTitle = document.title;
1890 window.addEventListener("popstate", function(e) {
1891 var params = getQueryStringParams();
1892 // Revert to the previous title manually since the History
1893 // API ignores the title parameter.
1894 document.title = previousTitle;
1895 // When browsing forward to search results the previous
1896 // search will be repeated, so the currentResults are
1897 // cleared to ensure the search is successful.
1898 currentResults = null;
1899 // Synchronize search bar with query string state and
1900 // perform the search. This will empty the bar if there's
1901 // nothing there, which lets you really go back to a
1902 // previous state with nothing in the bar.
1903 if (params.search && params.search.length > 0) {
1904 search_input.value = params.search;
1905 // Some browsers fire "onpopstate" for every page load
1906 // (Chrome), while others fire the event only when actually
1907 // popping a state (Firefox), which is why search() is
1908 // called both here and at the end of the startSearch()
1912 search_input.value = "";
1913 // When browsing back from search results the main page
1914 // visibility must be reset.
1915 hideSearchResults();
1922 index = buildIndex(rawSearchIndex);
1925 // Draw a convenient sidebar of known crates if we have a listing
1926 if (rootPath === "../" || rootPath === "./") {
1927 var sidebar = document.getElementsByClassName("sidebar-elems")[0];
1929 var div = document.createElement("div");
1930 div.className = "block crate";
1931 div.innerHTML = "<h3>Crates</h3>";
1932 var ul = document.createElement("ul");
1933 div.appendChild(ul);
1936 for (var crate in rawSearchIndex) {
1937 if (!hasOwnProperty(rawSearchIndex, crate)) {
1943 for (var i = 0; i < crates.length; ++i) {
1944 var klass = "crate";
1945 if (rootPath !== "./" && crates[i] === window.currentCrate) {
1946 klass += " current";
1948 var link = document.createElement("a");
1949 link.href = rootPath + crates[i] + "/index.html";
1950 link.title = rawSearchIndex[crates[i]].doc;
1951 link.className = klass;
1952 link.textContent = crates[i];
1954 var li = document.createElement("li");
1955 li.appendChild(link);
1958 sidebar.appendChild(div);
1964 // delayed sidebar rendering.
1965 window.initSidebarItems = function(items) {
1966 var sidebar = document.getElementsByClassName("sidebar-elems")[0];
1967 var current = window.sidebarCurrent;
1969 function block(shortty, longty) {
1970 var filtered = items[shortty];
1975 var div = document.createElement("div");
1976 div.className = "block " + shortty;
1977 var h3 = document.createElement("h3");
1978 h3.textContent = longty;
1979 div.appendChild(h3);
1980 var ul = document.createElement("ul");
1982 var length = filtered.length;
1983 for (var i = 0; i < length; ++i) {
1984 var item = filtered[i];
1986 var desc = item[1]; // can be null
1988 var klass = shortty;
1989 if (name === current.name && shortty === current.ty) {
1990 klass += " current";
1993 if (shortty === "mod") {
1994 path = name + "/index.html";
1996 path = shortty + "." + name + ".html";
1998 var link = document.createElement("a");
1999 link.href = current.relpath + path;
2001 link.className = klass;
2002 link.textContent = name;
2003 var li = document.createElement("li");
2004 li.appendChild(link);
2007 div.appendChild(ul);
2009 sidebar.appendChild(div);
2013 block("primitive", "Primitive Types");
2014 block("mod", "Modules");
2015 block("macro", "Macros");
2016 block("struct", "Structs");
2017 block("enum", "Enums");
2018 block("union", "Unions");
2019 block("constant", "Constants");
2020 block("static", "Statics");
2021 block("trait", "Traits");
2022 block("fn", "Functions");
2023 block("type", "Type Definitions");
2024 block("foreigntype", "Foreign Types");
2025 block("keyword", "Keywords");
2026 block("traitalias", "Trait Aliases");
2029 window.register_implementors = function(imp) {
2030 var implementors = document.getElementById("implementors-list");
2031 var synthetic_implementors = document.getElementById("synthetic-implementors-list");
2033 if (synthetic_implementors) {
2034 // This `inlined_types` variable is used to avoid having the same implementation
2035 // showing up twice. For example "String" in the "Sync" doc page.
2037 // By the way, this is only used by and useful for traits implemented automatically
2038 // (like "Send" and "Sync").
2039 var inlined_types = new Set();
2040 onEachLazy(synthetic_implementors.getElementsByClassName("impl"), function(el) {
2041 var aliases = el.getAttribute("aliases");
2045 aliases.split(",").forEach(function(alias) {
2046 inlined_types.add(alias);
2051 var libs = Object.getOwnPropertyNames(imp);
2052 var llength = libs.length;
2053 for (var i = 0; i < llength; ++i) {
2054 if (libs[i] === currentCrate) { continue; }
2055 var structs = imp[libs[i]];
2057 var slength = structs.length;
2059 for (var j = 0; j < slength; ++j) {
2060 var struct = structs[j];
2062 var list = struct.synthetic ? synthetic_implementors : implementors;
2064 if (struct.synthetic) {
2065 var stlength = struct.types.length;
2066 for (var k = 0; k < stlength; k++) {
2067 if (inlined_types.has(struct.types[k])) {
2068 continue struct_loop;
2070 inlined_types.add(struct.types[k]);
2074 var code = document.createElement("code");
2075 code.innerHTML = struct.text;
2077 var x = code.getElementsByTagName("a");
2078 var xlength = x.length;
2079 for (var it = 0; it < xlength; it++) {
2080 var href = x[it].getAttribute("href");
2081 if (href && href.indexOf("http") !== 0) {
2082 x[it].setAttribute("href", rootPath + href);
2085 var display = document.createElement("h3");
2086 addClass(display, "impl");
2087 display.innerHTML = "<span class=\"in-band\"><table class=\"table-display\">" +
2088 "<tbody><tr><td><code>" + code.outerHTML + "</code></td><td></td></tr>" +
2089 "</tbody></table></span>";
2090 list.appendChild(display);
2094 if (window.pending_implementors) {
2095 window.register_implementors(window.pending_implementors);
2098 function labelForToggleButton(sectionIsCollapsed) {
2099 if (sectionIsCollapsed) {
2100 // button will expand the section
2103 // button will collapse the section
2104 // note that this text is also set in the HTML template in render.rs
2105 return "\u2212"; // "\u2212" is "−" minus sign
2108 function onEveryMatchingChild(elem, className, func) {
2109 if (elem && className && func) {
2110 var length = elem.childNodes.length;
2111 var nodes = elem.childNodes;
2112 for (var i = 0; i < length; ++i) {
2113 if (hasClass(nodes[i], className)) {
2116 onEveryMatchingChild(nodes[i], className, func);
2122 function toggleAllDocs(pageId, fromAutoCollapse) {
2123 var innerToggle = document.getElementById("toggle-all-docs");
2127 if (hasClass(innerToggle, "will-expand")) {
2128 updateLocalStorage("rustdoc-collapse", "false");
2129 removeClass(innerToggle, "will-expand");
2130 onEveryMatchingChild(innerToggle, "inner", function(e) {
2131 e.innerHTML = labelForToggleButton(false);
2133 innerToggle.title = "collapse all docs";
2134 if (fromAutoCollapse !== true) {
2135 onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
2136 collapseDocs(e, "show");
2140 updateLocalStorage("rustdoc-collapse", "true");
2141 addClass(innerToggle, "will-expand");
2142 onEveryMatchingChild(innerToggle, "inner", function(e) {
2143 var parent = e.parentNode;
2144 var superParent = null;
2147 superParent = parent.parentNode;
2149 if (!parent || !superParent || superParent.id !== "main" ||
2150 hasClass(parent, "impl") === false) {
2151 e.innerHTML = labelForToggleButton(true);
2154 innerToggle.title = "expand all docs";
2155 if (fromAutoCollapse !== true) {
2156 onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
2157 var parent = e.parentNode;
2158 var superParent = null;
2161 superParent = parent.parentNode;
2163 if (!parent || !superParent || superParent.id !== "main" ||
2164 hasClass(parent, "impl") === false) {
2165 collapseDocs(e, "hide", pageId);
2172 function collapseDocs(toggle, mode, pageId) {
2173 if (!toggle || !toggle.parentNode) {
2177 function adjustToggle(arg) {
2178 return function(e) {
2179 if (hasClass(e, "toggle-label")) {
2181 e.style.display = "inline-block";
2183 e.style.display = "none";
2186 if (hasClass(e, "inner")) {
2187 e.innerHTML = labelForToggleButton(arg);
2192 function implHider(addOrRemove, fullHide) {
2193 return function(n) {
2194 var is_method = hasClass(n, "method") || fullHide;
2195 if (is_method || hasClass(n, "type")) {
2196 if (is_method === true) {
2198 addClass(n, "hidden-by-impl-hider");
2200 removeClass(n, "hidden-by-impl-hider");
2203 var ns = n.nextElementSibling;
2204 while (ns && (hasClass(ns, "docblock") || hasClass(ns, "stability"))) {
2206 addClass(ns, "hidden-by-impl-hider");
2208 removeClass(ns, "hidden-by-impl-hider");
2210 ns = ns.nextElementSibling;
2218 if (hasClass(toggle.parentNode, "impl") === false) {
2219 relatedDoc = toggle.parentNode.nextElementSibling;
2220 if (hasClass(relatedDoc, "stability")) {
2221 relatedDoc = relatedDoc.nextElementSibling;
2223 if (hasClass(relatedDoc, "docblock") || hasClass(relatedDoc, "sub-variant")) {
2224 if (mode === "toggle") {
2225 if (hasClass(relatedDoc, "hidden-by-usual-hider")) {
2231 if (action === "hide") {
2232 addClass(relatedDoc, "hidden-by-usual-hider");
2233 onEachLazy(toggle.childNodes, adjustToggle(true));
2234 addClass(toggle.parentNode, "collapsed");
2235 } else if (action === "show") {
2236 removeClass(relatedDoc, "hidden-by-usual-hider");
2237 removeClass(toggle.parentNode, "collapsed");
2238 onEachLazy(toggle.childNodes, adjustToggle(false));
2242 // we are collapsing the impl block(s).
2244 var parentElem = toggle.parentNode;
2245 relatedDoc = parentElem;
2246 var docblock = relatedDoc.nextElementSibling;
2248 while (hasClass(relatedDoc, "impl-items") === false) {
2249 relatedDoc = relatedDoc.nextElementSibling;
2252 if (!relatedDoc && hasClass(docblock, "docblock") === false) {
2256 // Hide all functions, but not associated types/consts.
2258 if (mode === "toggle") {
2259 if (hasClass(relatedDoc, "fns-now-collapsed") ||
2260 hasClass(docblock, "hidden-by-impl-hider")) {
2267 var dontApplyBlockRule = toggle.parentNode.parentNode.id !== "main";
2268 if (action === "show") {
2269 removeClass(relatedDoc, "fns-now-collapsed");
2270 removeClass(docblock, "hidden-by-usual-hider");
2271 onEachLazy(toggle.childNodes, adjustToggle(false, dontApplyBlockRule));
2272 onEachLazy(relatedDoc.childNodes, implHider(false, dontApplyBlockRule));
2273 } else if (action === "hide") {
2274 addClass(relatedDoc, "fns-now-collapsed");
2275 addClass(docblock, "hidden-by-usual-hider");
2276 onEachLazy(toggle.childNodes, adjustToggle(true, dontApplyBlockRule));
2277 onEachLazy(relatedDoc.childNodes, implHider(true, dontApplyBlockRule));
2282 function collapser(pageId, e, collapse) {
2283 // inherent impl ids are like "impl" or impl-<number>'.
2284 // they will never be hidden by default.
2285 var n = e.parentElement;
2286 if (n.id.match(/^impl(?:-\d+)?$/) === null) {
2287 // Automatically minimize all non-inherent impls
2288 if (collapse || hasClass(n, "impl")) {
2289 collapseDocs(e, "hide", pageId);
2294 function autoCollapse(pageId, collapse) {
2296 toggleAllDocs(pageId, true);
2297 } else if (getCurrentValue("rustdoc-auto-hide-trait-implementations") !== "false") {
2298 var impl_list = document.getElementById("trait-implementations-list");
2300 if (impl_list !== null) {
2301 onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
2302 collapser(pageId, e, collapse);
2306 var blanket_list = document.getElementById("blanket-implementations-list");
2308 if (blanket_list !== null) {
2309 onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
2310 collapser(pageId, e, collapse);
2316 var toggles = document.getElementById("toggle-all-docs");
2318 toggles.onclick = toggleAllDocs;
2321 function insertAfter(newNode, referenceNode) {
2322 referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
2325 function createSimpleToggle(sectionIsCollapsed) {
2326 var toggle = document.createElement("a");
2327 toggle.href = "javascript:void(0)";
2328 toggle.className = "collapse-toggle";
2329 toggle.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(sectionIsCollapsed) +
2334 function createToggle(toggle, otherMessage, fontSize, extraClass, show) {
2335 var span = document.createElement("span");
2336 span.className = "toggle-label";
2338 span.style.display = "none";
2340 if (!otherMessage) {
2341 span.innerHTML = " Expand description";
2343 span.innerHTML = otherMessage;
2347 span.style.fontSize = fontSize;
2350 var mainToggle = toggle.cloneNode(true);
2351 mainToggle.appendChild(span);
2353 var wrapper = document.createElement("div");
2354 wrapper.className = "toggle-wrapper";
2356 addClass(wrapper, "collapsed");
2357 var inner = mainToggle.getElementsByClassName("inner");
2358 if (inner && inner.length > 0) {
2359 inner[0].innerHTML = "+";
2363 addClass(wrapper, extraClass);
2365 wrapper.appendChild(mainToggle);
2370 var toggle = createSimpleToggle(false);
2371 var hideMethodDocs = getCurrentValue("rustdoc-auto-hide-method-docs") === "true";
2372 var hideImplementors = getCurrentValue("rustdoc-auto-collapse-implementors") !== "false";
2373 var pageId = getPageId();
2375 var func = function(e) {
2376 var next = e.nextElementSibling;
2380 if (hasClass(next, "docblock") === true ||
2381 (hasClass(next, "stability") === true &&
2382 hasClass(next.nextElementSibling, "docblock") === true)) {
2383 var newToggle = toggle.cloneNode(true);
2384 insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
2385 if (hideMethodDocs === true && hasClass(e, "method") === true) {
2386 collapseDocs(newToggle, "hide", pageId);
2391 var funcImpl = function(e) {
2392 var next = e.nextElementSibling;
2393 if (next && hasClass(next, "docblock")) {
2394 next = next.nextElementSibling;
2399 if (hasClass(e, "impl") &&
2400 (next.getElementsByClassName("method").length > 0 ||
2401 next.getElementsByClassName("associatedconstant").length > 0)) {
2402 var newToggle = toggle.cloneNode(true);
2403 insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
2404 // In case the option "auto-collapse implementors" is not set to false, we collapse
2405 // all implementors.
2406 if (hideImplementors === true && e.parentNode.id === "implementors-list") {
2407 collapseDocs(newToggle, "hide", pageId);
2412 onEachLazy(document.getElementsByClassName("method"), func);
2413 onEachLazy(document.getElementsByClassName("associatedconstant"), func);
2414 onEachLazy(document.getElementsByClassName("impl"), funcImpl);
2415 var impl_call = function() {};
2416 if (hideMethodDocs === true) {
2417 impl_call = function(e, newToggle) {
2418 if (e.id.match(/^impl(?:-\d+)?$/) === null) {
2419 // Automatically minimize all non-inherent impls
2420 if (hasClass(e, "impl") === true) {
2421 collapseDocs(newToggle, "hide", pageId);
2426 var newToggle = document.createElement("a");
2427 newToggle.href = "javascript:void(0)";
2428 newToggle.className = "collapse-toggle hidden-default collapsed";
2429 newToggle.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(true) +
2430 "</span>] Show hidden undocumented items";
2431 function toggleClicked() {
2432 if (hasClass(this, "collapsed")) {
2433 removeClass(this, "collapsed");
2434 onEachLazy(this.parentNode.getElementsByClassName("hidden"), function(x) {
2435 if (hasClass(x, "content") === false) {
2436 removeClass(x, "hidden");
2440 this.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(false) +
2441 "</span>] Hide undocumented items";
2443 addClass(this, "collapsed");
2444 onEachLazy(this.parentNode.getElementsByClassName("x"), function(x) {
2445 if (hasClass(x, "content") === false) {
2446 addClass(x, "hidden");
2447 removeClass(x, "x");
2450 this.innerHTML = "[<span class=\"inner\">" + labelForToggleButton(true) +
2451 "</span>] Show hidden undocumented items";
2454 onEachLazy(document.getElementsByClassName("impl-items"), function(e) {
2455 onEachLazy(e.getElementsByClassName("associatedconstant"), func);
2456 var hiddenElems = e.getElementsByClassName("hidden");
2457 var needToggle = false;
2459 var hlength = hiddenElems.length;
2460 for (var i = 0; i < hlength; ++i) {
2461 if (hasClass(hiddenElems[i], "content") === false &&
2462 hasClass(hiddenElems[i], "docblock") === false) {
2467 if (needToggle === true) {
2468 var inner_toggle = newToggle.cloneNode(true);
2469 inner_toggle.onclick = toggleClicked;
2470 e.insertBefore(inner_toggle, e.firstChild);
2471 impl_call(e.previousSibling, inner_toggle);
2475 var currentType = document.getElementsByClassName("type-decl")[0];
2476 var className = null;
2478 currentType = currentType.getElementsByClassName("rust")[0];
2480 currentType.classList.forEach(function(item) {
2481 if (item !== "main") {
2488 var showItemDeclarations = getCurrentValue("rustdoc-auto-hide-" + className);
2489 if (showItemDeclarations === null) {
2490 if (className === "enum" || className === "macro") {
2491 showItemDeclarations = "false";
2492 } else if (className === "struct" || className === "union" || className === "trait") {
2493 showItemDeclarations = "true";
2495 // In case we found an unknown type, we just use the "parent" value.
2496 showItemDeclarations = getCurrentValue("rustdoc-auto-hide-declarations");
2499 showItemDeclarations = showItemDeclarations === "false";
2500 function buildToggleWrapper(e) {
2501 if (hasClass(e, "autohide")) {
2502 var wrap = e.previousElementSibling;
2503 if (wrap && hasClass(wrap, "toggle-wrapper")) {
2504 var inner_toggle = wrap.childNodes[0];
2505 var extra = e.childNodes[0].tagName === "H3";
2507 e.style.display = "none";
2508 addClass(wrap, "collapsed");
2509 onEachLazy(inner_toggle.getElementsByClassName("inner"), function(e) {
2510 e.innerHTML = labelForToggleButton(true);
2512 onEachLazy(inner_toggle.getElementsByClassName("toggle-label"), function(e) {
2513 e.style.display = "inline-block";
2514 if (extra === true) {
2515 e.innerHTML = " Show " + e.childNodes[0].innerHTML;
2520 if (e.parentNode.id === "main") {
2521 var otherMessage = "";
2525 if (hasClass(e, "type-decl")) {
2527 otherMessage = " Show declaration";
2528 if (showItemDeclarations === false) {
2529 extraClass = "collapsed";
2531 } else if (hasClass(e, "sub-variant")) {
2532 otherMessage = " Show fields";
2533 } else if (hasClass(e, "non-exhaustive")) {
2534 otherMessage = " This ";
2535 if (hasClass(e, "non-exhaustive-struct")) {
2536 otherMessage += "struct";
2537 } else if (hasClass(e, "non-exhaustive-enum")) {
2538 otherMessage += "enum";
2539 } else if (hasClass(e, "non-exhaustive-variant")) {
2540 otherMessage += "enum variant";
2541 } else if (hasClass(e, "non-exhaustive-type")) {
2542 otherMessage += "type";
2544 otherMessage += " is marked as non-exhaustive";
2545 } else if (hasClass(e.childNodes[0], "impl-items")) {
2546 extraClass = "marg-left";
2549 e.parentNode.insertBefore(
2555 hasClass(e, "type-decl") === false || showItemDeclarations === true),
2557 if (hasClass(e, "type-decl") === true && showItemDeclarations === true) {
2558 collapseDocs(e.previousSibling.childNodes[0], "toggle");
2560 if (hasClass(e, "non-exhaustive") === true) {
2561 collapseDocs(e.previousSibling.childNodes[0], "toggle");
2566 onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
2567 onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
2568 var pageId = getPageId();
2570 autoCollapse(pageId, getCurrentValue("rustdoc-collapse") === "true");
2572 if (pageId !== null) {
2573 expandSection(pageId);
2577 function createToggleWrapper(tog) {
2578 var span = document.createElement("span");
2579 span.className = "toggle-label";
2580 span.style.display = "none";
2581 span.innerHTML = " Expand attributes";
2582 tog.appendChild(span);
2584 var wrapper = document.createElement("div");
2585 wrapper.className = "toggle-wrapper toggle-attributes";
2586 wrapper.appendChild(tog);
2591 // To avoid checking on "rustdoc-item-attributes" value on every loop...
2592 var itemAttributesFunc = function() {};
2593 if (getCurrentValue("rustdoc-auto-hide-attributes") !== "false") {
2594 itemAttributesFunc = function(x) {
2595 collapseDocs(x.previousSibling.childNodes[0], "toggle");
2598 var attributesToggle = createToggleWrapper(createSimpleToggle(false));
2599 onEachLazy(main.getElementsByClassName("attributes"), function(i_e) {
2600 var attr_tog = attributesToggle.cloneNode(true);
2601 if (hasClass(i_e, "top-attr") === true) {
2602 addClass(attr_tog, "top-attr");
2604 i_e.parentNode.insertBefore(attr_tog, i_e);
2605 itemAttributesFunc(i_e);
2610 // To avoid checking on "rustdoc-line-numbers" value on every loop...
2611 var lineNumbersFunc = function() {};
2612 if (getCurrentValue("rustdoc-line-numbers") === "true") {
2613 lineNumbersFunc = function(x) {
2614 var count = x.textContent.split("\n").length;
2616 for (var i = 0; i < count; ++i) {
2619 var node = document.createElement("pre");
2620 addClass(node, "line-number");
2621 node.innerHTML = elems.join("\n");
2622 x.parentNode.insertBefore(node, x);
2625 onEachLazy(document.getElementsByClassName("rust-example-rendered"), function(e) {
2626 if (hasClass(e, "compile_fail")) {
2627 e.addEventListener("mouseover", function() {
2628 this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00";
2630 e.addEventListener("mouseout", function() {
2631 this.parentElement.previousElementSibling.childNodes[0].style.color = "";
2633 } else if (hasClass(e, "ignore")) {
2634 e.addEventListener("mouseover", function() {
2635 this.parentElement.previousElementSibling.childNodes[0].style.color = "#ff9200";
2637 e.addEventListener("mouseout", function() {
2638 this.parentElement.previousElementSibling.childNodes[0].style.color = "";
2645 onEachLazy(document.getElementsByClassName("notable-traits"), function(e) {
2646 e.onclick = function() {
2647 this.getElementsByClassName('notable-traits-tooltiptext')[0]
2648 .classList.toggle("force-tooltip");
2652 // In the search display, allows to switch between tabs.
2653 function printTab(nb) {
2654 if (nb === 0 || nb === 1 || nb === 2) {
2658 onEachLazy(document.getElementById("titles").childNodes, function(elem) {
2659 if (nb_copy === 0) {
2660 addClass(elem, "selected");
2662 removeClass(elem, "selected");
2666 onEachLazy(document.getElementById("results").childNodes, function(elem) {
2668 elem.style.display = "";
2670 elem.style.display = "none";
2676 function putBackSearch(search_input) {
2677 var search = getSearchElement();
2678 if (search_input.value !== "" && hasClass(search, "hidden")) {
2679 showSearchResults(search);
2680 if (browserSupportsHistoryApi()) {
2681 history.replaceState(search_input.value,
2683 "?search=" + encodeURIComponent(search_input.value));
2688 function getSearchLoadingText() {
2689 return "Loading search results...";
2693 search_input.onfocus = function() {
2694 putBackSearch(this);
2698 var params = getQueryStringParams();
2699 if (params && params.search) {
2700 var search = getSearchElement();
2701 search.innerHTML = "<h3 style=\"text-align: center;\">" + getSearchLoadingText() + "</h3>";
2702 showSearchResults(search);
2705 var sidebar_menu = document.getElementsByClassName("sidebar-menu")[0];
2707 sidebar_menu.onclick = function() {
2708 var sidebar = document.getElementsByClassName("sidebar")[0];
2709 if (hasClass(sidebar, "mobile") === true) {
2717 window.onresize = function() {
2722 onEachLazy(main.getElementsByClassName("loading-content"), function(e) {
2725 onEachLazy(main.childNodes, function(e) {
2726 // Unhide the actual content once loading is complete. Headers get
2727 // flex treatment for their horizontal layout, divs get block treatment
2728 // for vertical layout (column-oriented flex layout for divs caused
2729 // errors in mobile browsers).
2730 if (e.tagName === "H2" || e.tagName === "H3") {
2731 var nextTagName = e.nextElementSibling.tagName;
2732 if (nextTagName == "H2" || nextTagName == "H3") {
2733 e.nextElementSibling.style.display = "flex";
2735 e.nextElementSibling.style.display = "block";
2741 window.addSearchOptions = function(crates) {
2742 var elem = document.getElementById("crate-search");
2747 var crates_text = [];
2748 if (Object.keys(crates).length > 1) {
2749 for (var crate in crates) {
2750 if (hasOwnProperty(crates, crate)) {
2751 crates_text.push(crate);
2755 crates_text.sort(function(a, b) {
2756 var lower_a = a.toLowerCase();
2757 var lower_b = b.toLowerCase();
2759 if (lower_a < lower_b) {
2761 } else if (lower_a > lower_b) {
2766 var savedCrate = getCurrentValue("rustdoc-saved-filter-crate");
2767 for (var i = 0; i < crates_text.length; ++i) {
2768 var option = document.createElement("option");
2769 option.value = crates_text[i];
2770 option.innerText = crates_text[i];
2771 elem.appendChild(option);
2772 // Set the crate filter from saved storage, if the current page has the saved crate
2775 // If not, ignore the crate filter -- we want to support filtering for crates on sites
2776 // like doc.rust-lang.org where the crates may differ from page to page while on the
2778 if (crates_text[i] === savedCrate) {
2779 elem.value = savedCrate;
2784 search_input.removeAttribute('disabled');
2788 function buildHelperPopup() {
2789 var popup = document.createElement("aside");
2790 addClass(popup, "hidden");
2793 var container = document.createElement("div");
2795 ["?", "Show this help dialog"],
2796 ["S", "Focus the search field"],
2797 ["↑", "Move up in search results"],
2798 ["↓", "Move down in search results"],
2799 ["↹", "Switch tab"],
2800 ["⏎", "Go to active search result"],
2801 ["+", "Expand all sections"],
2802 ["-", "Collapse all sections"],
2803 ].map(x => "<dt><kbd>" + x[0] + "</kbd></dt><dd>" + x[1] + "</dd>").join("");
2804 var div_shortcuts = document.createElement("div");
2805 addClass(div_shortcuts, "shortcuts");
2806 div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
2809 "Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
2810 restrict the search to a given type.",
2811 "Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
2812 <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \
2813 and <code>const</code>.",
2814 "Search functions by type signature (e.g., <code>vec -> usize</code> or \
2815 <code>* -> vec</code>)",
2816 "Search multiple things at once by splitting your query with comma (e.g., \
2817 <code>str,u8</code> or <code>String,struct:Vec,test</code>)",
2818 "You can look for items with an exact name by putting double quotes around \
2819 your request: <code>\"string\"</code>",
2820 "Look for items inside another one by searching for a path: <code>vec::Vec</code>",
2821 ].map(x => "<p>" + x + "</p>").join("");
2822 var div_infos = document.createElement("div");
2823 addClass(div_infos, "infos");
2824 div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;
2826 container.appendChild(div_shortcuts);
2827 container.appendChild(div_infos);
2829 popup.appendChild(container);
2830 insertAfter(popup, getSearchElement());
2834 window.onhashchange = onHashChange;
2839 // This is required in firefox. Explanations: when going back in the history, firefox doesn't re-run
2840 // the JS, therefore preventing rustdoc from setting a few things required to be able to reload the
2841 // previous search results (if you navigated to a search result with the keyboard, pressed enter on
2842 // it to navigate to that result, and then came back to this page).
2843 window.onunload = function(){};