")) {
return tmp.slice(0, tmp.length - 6);
}
return tmp;
}
function addTab(array, query, display) {
var extraStyle = "";
if (display === false) {
extraStyle = " style=\"display: none;\"";
}
var output = "";
var duplicates = {};
var length = 0;
if (array.length > 0) {
output = "";
} else {
output = "No results :(
" +
"Try on
DuckDuckGo?
" +
"Or try looking in one of these:
";
}
return [output, length];
}
function makeTabHeader(tabNb, text, nbElems) {
if (currentTab === tabNb) {
return "" + text +
"
(" + nbElems + ")
";
}
return "" + text + "
(" + nbElems + ")
";
}
function showResults(results) {
if (results.others.length === 1 &&
getCurrentValue("rustdoc-go-to-only-result") === "true") {
var elem = document.createElement("a");
elem.href = results.others[0].href;
elem.style.display = "none";
// For firefox, we need the element to be in the DOM so it can be clicked.
document.body.appendChild(elem);
elem.click();
}
var query = getQuery(search_input.value);
currentResults = query.id;
var ret_others = addTab(results.others, query);
var ret_in_args = addTab(results.in_args, query, false);
var ret_returned = addTab(results.returned, query, false);
var output = "Results for " + escape(query.query) +
(query.type ? " (type: " + escape(query.type) + ")" : "") + "
" +
"" +
makeTabHeader(0, "In Names", ret_others[1]) +
makeTabHeader(1, "In Parameters", ret_in_args[1]) +
makeTabHeader(2, "In Return Types", ret_returned[1]) +
"
" +
ret_others[0] + ret_in_args[0] + ret_returned[0] + "
";
addClass(main, "hidden");
var search = document.getElementById("search");
removeClass(search, "hidden");
search.innerHTML = output;
var tds = search.getElementsByTagName("td");
var td_width = 0;
if (tds.length > 0) {
td_width = tds[0].offsetWidth;
}
var width = search.offsetWidth - 40 - td_width;
onEachLazy(search.getElementsByClassName("desc"), function(e) {
e.style.width = width + "px";
});
initSearchNav();
var elems = document.getElementById("titles").childNodes;
elems[0].onclick = function() { printTab(0); };
elems[1].onclick = function() { printTab(1); };
elems[2].onclick = function() { printTab(2); };
printTab(currentTab);
}
function execSearch(query, searchWords, filterCrates) {
function getSmallest(arrays, positions, notDuplicates) {
var start = null;
for (var it = 0; it < positions.length; ++it) {
if (arrays[it].length > positions[it] &&
(start === null || start > arrays[it][positions[it]].lev) &&
!notDuplicates[arrays[it][positions[it]].fullPath]) {
start = arrays[it][positions[it]].lev;
}
}
return start;
}
function mergeArrays(arrays) {
var ret = [];
var positions = [];
var notDuplicates = {};
for (var x = 0; x < arrays.length; ++x) {
positions.push(0);
}
while (ret.length < MAX_RESULTS) {
var smallest = getSmallest(arrays, positions, notDuplicates);
if (smallest === null) {
break;
}
for (x = 0; x < arrays.length && ret.length < MAX_RESULTS; ++x) {
if (arrays[x].length > positions[x] &&
arrays[x][positions[x]].lev === smallest &&
!notDuplicates[arrays[x][positions[x]].fullPath]) {
ret.push(arrays[x][positions[x]]);
notDuplicates[arrays[x][positions[x]].fullPath] = true;
positions[x] += 1;
}
}
}
return ret;
}
var queries = query.raw.split(",");
var results = {
"in_args": [],
"returned": [],
"others": [],
};
for (var i = 0; i < queries.length; ++i) {
query = queries[i].trim();
if (query.length !== 0) {
var tmp = execQuery(getQuery(query), searchWords, filterCrates);
results.in_args.push(tmp.in_args);
results.returned.push(tmp.returned);
results.others.push(tmp.others);
}
}
if (queries.length > 1) {
return {
"in_args": mergeArrays(results.in_args),
"returned": mergeArrays(results.returned),
"others": mergeArrays(results.others),
};
} else {
return {
"in_args": results.in_args[0],
"returned": results.returned[0],
"others": results.others[0],
};
}
}
function getFilterCrates() {
var elem = document.getElementById("crate-search");
if (elem && elem.value !== "All crates" && rawSearchIndex.hasOwnProperty(elem.value)) {
return elem.value;
}
return undefined;
}
function search(e, forced) {
var params = getQueryStringParams();
var query = getQuery(search_input.value.trim());
if (e) {
e.preventDefault();
}
if (query.query.length === 0) {
return;
}
if (forced !== true && query.id === currentResults) {
if (query.query.length > 0) {
putBackSearch(search_input);
}
return;
}
// Update document title to maintain a meaningful browser history
document.title = "Results for " + query.query + " - Rust";
// Because searching is incremental by character, only the most
// recent search query is added to the browser history.
if (browserSupportsHistoryApi()) {
if (!history.state && !params.search) {
history.pushState(query, "", "?search=" + encodeURIComponent(query.raw));
} else {
history.replaceState(query, "", "?search=" + encodeURIComponent(query.raw));
}
}
var filterCrates = getFilterCrates();
showResults(execSearch(query, index, filterCrates), filterCrates);
}
function buildIndex(rawSearchIndex) {
searchIndex = [];
var searchWords = [];
var i;
for (var crate in rawSearchIndex) {
if (!rawSearchIndex.hasOwnProperty(crate)) { continue; }
searchWords.push(crate);
searchIndex.push({
crate: crate,
ty: 1, // == ExternCrate
name: crate,
path: "",
desc: rawSearchIndex[crate].doc,
type: null,
});
// an array of [(Number) item type,
// (String) name,
// (String) full path or empty string for previous path,
// (String) description,
// (Number | null) the parent path index to `paths`]
// (Object | null) the type of the function (if any)
var items = rawSearchIndex[crate].i;
// an array of [(Number) item type,
// (String) name]
var paths = rawSearchIndex[crate].p;
// convert `paths` into an object form
var len = paths.length;
for (i = 0; i < len; ++i) {
paths[i] = {ty: paths[i][0], name: paths[i][1]};
}
// convert `items` into an object form, and construct word indices.
//
// before any analysis is performed lets gather the search terms to
// search against apart from the rest of the data. This is a quick
// operation that is cached for the life of the page state so that
// all other search operations have access to this cached data for
// faster analysis operations
len = items.length;
var lastPath = "";
for (i = 0; i < len; ++i) {
var rawRow = items[i];
var row = {crate: crate, ty: rawRow[0], name: rawRow[1],
path: rawRow[2] || lastPath, desc: rawRow[3],
parent: paths[rawRow[4]], type: rawRow[5]};
searchIndex.push(row);
if (typeof row.name === "string") {
var word = row.name.toLowerCase();
searchWords.push(word);
} else {
searchWords.push("");
}
lastPath = row.path;
}
}
return searchWords;
}
function startSearch() {
var searchTimeout;
var callback = function() {
clearTimeout(searchTimeout);
if (search_input.value.length === 0) {
if (browserSupportsHistoryApi()) {
history.replaceState("", window.currentCrate + " - Rust", "?search=");
}
if (hasClass(main, "content")) {
removeClass(main, "hidden");
}
var search_c = document.getElementById("search");
if (hasClass(search_c, "content")) {
addClass(search_c, "hidden");
}
} else {
searchTimeout = setTimeout(search, 500);
}
};
search_input.onkeyup = callback;
search_input.oninput = callback;
document.getElementsByClassName("search-form")[0].onsubmit = function(e) {
e.preventDefault();
clearTimeout(searchTimeout);
search();
};
search_input.onchange = function(e) {
// Do NOT e.preventDefault() here. It will prevent pasting.
clearTimeout(searchTimeout);
// zero-timeout necessary here because at the time of event handler execution the
// pasted content is not in the input field yet. Shouldn’t make any difference for
// change, though.
setTimeout(search, 0);
};
search_input.onpaste = search_input.onchange;
var selectCrate = document.getElementById('crate-search');
if (selectCrate) {
selectCrate.onchange = function() {
search(undefined, true);
};
}
// Push and pop states are used to add search results to the browser
// history.
if (browserSupportsHistoryApi()) {
// Store the previous so we can revert back to it later.
var previousTitle = document.title;
window.onpopstate = function(e) {
var params = getQueryStringParams();
// When browsing back from search results the main page
// visibility must be reset.
if (!params.search) {
if (hasClass(main, "content")) {
removeClass(main, "hidden");
}
var search_c = document.getElementById("search");
if (hasClass(search_c, "content")) {
addClass(search_c, "hidden");
}
}
// Revert to the previous title manually since the History
// API ignores the title parameter.
document.title = previousTitle;
// When browsing forward to search results the previous
// search will be repeated, so the currentResults are
// cleared to ensure the search is successful.
currentResults = null;
// Synchronize search bar with query string state and
// perform the search. This will empty the bar if there's
// nothing there, which lets you really go back to a
// previous state with nothing in the bar.
if (params.search) {
search_input.value = params.search;
} else {
search_input.value = "";
}
// Some browsers fire "onpopstate" for every page load
// (Chrome), while others fire the event only when actually
// popping a state (Firefox), which is why search() is
// called both here and at the end of the startSearch()
// function.
search();
};
}
search();
}
index = buildIndex(rawSearchIndex);
startSearch();
// Draw a convenient sidebar of known crates if we have a listing
if (rootPath === "../" || rootPath === "./") {
var sidebar = document.getElementsByClassName("sidebar-elems")[0];
if (sidebar) {
var div = document.createElement("div");
div.className = "block crate";
div.innerHTML = "Crates
";
var ul = document.createElement("ul");
div.appendChild(ul);
var crates = [];
for (var crate in rawSearchIndex) {
if (!rawSearchIndex.hasOwnProperty(crate)) {
continue;
}
crates.push(crate);
}
crates.sort();
for (var i = 0; i < crates.length; ++i) {
var klass = "crate";
if (rootPath !== "./" && crates[i] === window.currentCrate) {
klass += " current";
}
var link = document.createElement("a");
link.href = rootPath + crates[i] + "/index.html";
link.title = rawSearchIndex[crates[i]].doc;
link.className = klass;
link.textContent = crates[i];
var li = document.createElement("li");
li.appendChild(link);
ul.appendChild(li);
}
sidebar.appendChild(div);
}
}
}
window.initSearch = initSearch;
// delayed sidebar rendering.
function initSidebarItems(items) {
var sidebar = document.getElementsByClassName("sidebar-elems")[0];
var current = window.sidebarCurrent;
function block(shortty, longty) {
var filtered = items[shortty];
if (!filtered) {
return;
}
var div = document.createElement("div");
div.className = "block " + shortty;
var h3 = document.createElement("h3");
h3.textContent = longty;
div.appendChild(h3);
var ul = document.createElement("ul");
var length = filtered.length;
for (var i = 0; i < length; ++i) {
var item = filtered[i];
var name = item[0];
var desc = item[1]; // can be null
var klass = shortty;
if (name === current.name && shortty === current.ty) {
klass += " current";
}
var path;
if (shortty === "mod") {
path = name + "/index.html";
} else {
path = shortty + "." + name + ".html";
}
var link = document.createElement("a");
link.href = current.relpath + path;
link.title = desc;
link.className = klass;
link.textContent = name;
var li = document.createElement("li");
li.appendChild(link);
ul.appendChild(li);
}
div.appendChild(ul);
if (sidebar) {
sidebar.appendChild(div);
}
}
block("primitive", "Primitive Types");
block("mod", "Modules");
block("macro", "Macros");
block("struct", "Structs");
block("enum", "Enums");
block("union", "Unions");
block("constant", "Constants");
block("static", "Statics");
block("trait", "Traits");
block("fn", "Functions");
block("type", "Type Definitions");
block("foreigntype", "Foreign Types");
block("keyword", "Keywords");
block("traitalias", "Trait Aliases");
}
window.initSidebarItems = initSidebarItems;
window.register_implementors = function(imp) {
var implementors = document.getElementById("implementors-list");
var synthetic_implementors = document.getElementById("synthetic-implementors-list");
var libs = Object.getOwnPropertyNames(imp);
var llength = libs.length;
for (var i = 0; i < llength; ++i) {
if (libs[i] === currentCrate) { continue; }
var structs = imp[libs[i]];
var slength = structs.length;
struct_loop:
for (var j = 0; j < slength; ++j) {
var struct = structs[j];
var list = struct.synthetic ? synthetic_implementors : implementors;
if (struct.synthetic) {
var stlength = struct.types.length;
for (var k = 0; k < stlength; k++) {
if (window.inlined_types.has(struct.types[k])) {
continue struct_loop;
}
window.inlined_types.add(struct.types[k]);
}
}
var code = document.createElement("code");
code.innerHTML = struct.text;
var x = code.getElementsByTagName("a");
var xlength = x.length;
for (var it = 0; it < xlength; it++) {
var href = x[it].getAttribute("href");
if (href && href.indexOf("http") !== 0) {
x[it].setAttribute("href", rootPath + href);
}
}
var display = document.createElement("h3");
addClass(display, "impl");
display.innerHTML = "" +
"" + code.outerHTML + " | |
" +
"
";
list.appendChild(display);
}
}
};
if (window.pending_implementors) {
window.register_implementors(window.pending_implementors);
}
function labelForToggleButton(sectionIsCollapsed) {
if (sectionIsCollapsed) {
// button will expand the section
return "+";
}
// button will collapse the section
// note that this text is also set in the HTML template in render.rs
return "\u2212"; // "\u2212" is "−" minus sign
}
function onEveryMatchingChild(elem, className, func) {
if (elem && className && func) {
var length = elem.childNodes.length;
var nodes = elem.childNodes;
for (var i = 0; i < length; ++i) {
if (hasClass(nodes[i], className)) {
func(nodes[i]);
} else {
onEveryMatchingChild(nodes[i], className, func);
}
}
}
}
function toggleAllDocs(pageId, fromAutoCollapse) {
var innerToggle = document.getElementById("toggle-all-docs");
if (!innerToggle) {
return;
}
if (hasClass(innerToggle, "will-expand")) {
updateLocalStorage("rustdoc-collapse", "false");
removeClass(innerToggle, "will-expand");
onEveryMatchingChild(innerToggle, "inner", function(e) {
e.innerHTML = labelForToggleButton(false);
});
innerToggle.title = "collapse all docs";
if (fromAutoCollapse !== true) {
onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
collapseDocs(e, "show");
});
}
} else {
updateLocalStorage("rustdoc-collapse", "true");
addClass(innerToggle, "will-expand");
onEveryMatchingChild(innerToggle, "inner", function(e) {
var parent = e.parentNode;
var superParent = null;
if (parent) {
superParent = parent.parentNode;
}
if (!parent || !superParent || superParent.id !== "main" ||
hasClass(parent, "impl") === false) {
e.innerHTML = labelForToggleButton(true);
}
});
innerToggle.title = "expand all docs";
if (fromAutoCollapse !== true) {
onEachLazy(document.getElementsByClassName("collapse-toggle"), function(e) {
var parent = e.parentNode;
var superParent = null;
if (parent) {
superParent = parent.parentNode;
}
if (!parent || !superParent || superParent.id !== "main" ||
hasClass(parent, "impl") === false) {
collapseDocs(e, "hide", pageId);
}
});
}
}
}
function collapseDocs(toggle, mode, pageId) {
if (!toggle || !toggle.parentNode) {
return;
}
function adjustToggle(arg) {
return function(e) {
if (hasClass(e, "toggle-label")) {
if (arg) {
e.style.display = "inline-block";
} else {
e.style.display = "none";
}
}
if (hasClass(e, "inner")) {
e.innerHTML = labelForToggleButton(arg);
}
};
}
function implHider(addOrRemove, fullHide) {
return function(n) {
var is_method = hasClass(n, "method") || fullHide;
if (is_method || hasClass(n, "type")) {
if (is_method === true) {
if (addOrRemove) {
addClass(n, "hidden-by-impl-hider");
} else {
removeClass(n, "hidden-by-impl-hider");
}
}
var ns = n.nextElementSibling;
while (true) {
if (ns && (
hasClass(ns, "docblock") ||
hasClass(ns, "stability"))) {
if (addOrRemove) {
addClass(ns, "hidden-by-impl-hider");
} else {
removeClass(ns, "hidden-by-impl-hider");
}
ns = ns.nextElementSibling;
continue;
}
break;
}
}
};
}
var relatedDoc;
var action = mode;
if (hasClass(toggle.parentNode, "impl") === false) {
relatedDoc = toggle.parentNode.nextElementSibling;
if (hasClass(relatedDoc, "stability")) {
relatedDoc = relatedDoc.nextElementSibling;
}
if (hasClass(relatedDoc, "docblock") || hasClass(relatedDoc, "sub-variant")) {
if (mode === "toggle") {
if (hasClass(relatedDoc, "hidden-by-usual-hider")) {
action = "show";
} else {
action = "hide";
}
}
if (action === "hide") {
addClass(relatedDoc, "hidden-by-usual-hider");
onEachLazy(toggle.childNodes, adjustToggle(true));
addClass(toggle.parentNode, "collapsed");
} else if (action === "show") {
removeClass(relatedDoc, "hidden-by-usual-hider");
removeClass(toggle.parentNode, "collapsed");
onEachLazy(toggle.childNodes, adjustToggle(false));
}
}
} else {
// we are collapsing the impl block(s).
var parentElem = toggle.parentNode;
relatedDoc = parentElem;
var docblock = relatedDoc.nextElementSibling;
while (hasClass(relatedDoc, "impl-items") === false) {
relatedDoc = relatedDoc.nextElementSibling;
}
if ((!relatedDoc && hasClass(docblock, "docblock") === false) ||
(pageId && document.getElementById(pageId))) {
return;
}
// Hide all functions, but not associated types/consts.
if (mode === "toggle") {
if (hasClass(relatedDoc, "fns-now-collapsed") ||
hasClass(docblock, "hidden-by-impl-hider")) {
action = "show";
} else {
action = "hide";
}
}
var dontApplyBlockRule = toggle.parentNode.parentNode.id !== "main";
if (action === "show") {
removeClass(relatedDoc, "fns-now-collapsed");
removeClass(docblock, "hidden-by-usual-hider");
onEachLazy(toggle.childNodes, adjustToggle(false, dontApplyBlockRule));
onEachLazy(relatedDoc.childNodes, implHider(false, dontApplyBlockRule));
} else if (action === "hide") {
addClass(relatedDoc, "fns-now-collapsed");
addClass(docblock, "hidden-by-usual-hider");
onEachLazy(toggle.childNodes, adjustToggle(true, dontApplyBlockRule));
onEachLazy(relatedDoc.childNodes, implHider(true, dontApplyBlockRule));
}
}
}
function collapser(e, collapse) {
// inherent impl ids are like "impl" or impl-'.
// they will never be hidden by default.
var n = e.parentElement;
if (n.id.match(/^impl(?:-\d+)?$/) === null) {
// Automatically minimize all non-inherent impls
if (collapse || hasClass(n, "impl")) {
collapseDocs(e, "hide", pageId);
}
}
}
function autoCollapse(pageId, collapse) {
if (collapse) {
toggleAllDocs(pageId, true);
} else if (getCurrentValue("rustdoc-trait-implementations") !== "false") {
var impl_list = document.getElementById("implementations-list");
if (impl_list !== null) {
onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) {
collapser(e, collapse);
});
}
var blanket_list = document.getElementById("blanket-implementations-list");
if (blanket_list !== null) {
onEachLazy(blanket_list.getElementsByClassName("collapse-toggle"), function(e) {
collapser(e, collapse);
});
}
}
}
var toggles = document.getElementById("toggle-all-docs");
if (toggles) {
toggles.onclick = toggleAllDocs;
}
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
function createSimpleToggle(sectionIsCollapsed) {
var toggle = document.createElement("a");
toggle.href = "javascript:void(0)";
toggle.className = "collapse-toggle";
toggle.innerHTML = "[" + labelForToggleButton(sectionIsCollapsed) +
"]";
return toggle;
}
var toggle = createSimpleToggle(false);
var hideMethodDocs = getCurrentValue("rustdoc-method-docs") === "true";
var pageId = getPageId();
var func = function(e) {
var next = e.nextElementSibling;
if (!next) {
return;
}
if (hasClass(next, "docblock") === true ||
(hasClass(next, "stability") === true &&
hasClass(next.nextElementSibling, "docblock") === true)) {
var newToggle = toggle.cloneNode(true);
insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]);
if (hideMethodDocs === true && hasClass(e, "method") === true) {
collapseDocs(newToggle, "hide", pageId);
}
}
};
var funcImpl = function(e) {
var next = e.nextElementSibling;
if (next && hasClass(next, "docblock")) {
next = next.nextElementSibling;
}
if (!next) {
return;
}
if (next.getElementsByClassName("method").length > 0 && hasClass(e, "impl")) {
insertAfter(toggle.cloneNode(true), e.childNodes[e.childNodes.length - 1]);
}
};
onEachLazy(document.getElementsByClassName("method"), func);
onEachLazy(document.getElementsByClassName("associatedconstant"), func);
onEachLazy(document.getElementsByClassName("impl"), funcImpl);
var impl_call = function() {};
if (hideMethodDocs === true) {
impl_call = function(e, newToggle, pageId) {
if (e.id.match(/^impl(?:-\d+)?$/) === null) {
// Automatically minimize all non-inherent impls
if (hasClass(e, "impl") === true) {
collapseDocs(newToggle, "hide", pageId);
}
}
};
}
var newToggle = document.createElement("a");
newToggle.href = "javascript:void(0)";
newToggle.className = "collapse-toggle hidden-default collapsed";
newToggle.innerHTML = "[" + labelForToggleButton(true) +
"] Show hidden undocumented items";
function toggleClicked() {
if (hasClass(this, "collapsed")) {
removeClass(this, "collapsed");
onEachLazy(this.parentNode.getElementsByClassName("hidden"), function(x) {
if (hasClass(x, "content") === false) {
removeClass(x, "hidden");
addClass(x, "x");
}
}, true);
this.innerHTML = "[" + labelForToggleButton(false) +
"] Hide undocumented items";
} else {
addClass(this, "collapsed");
onEachLazy(this.parentNode.getElementsByClassName("x"), function(x) {
if (hasClass(x, "content") === false) {
addClass(x, "hidden");
removeClass(x, "x");
}
}, true);
this.innerHTML = "[" + labelForToggleButton(true) +
"] Show hidden undocumented items";
}
}
onEachLazy(document.getElementsByClassName("impl-items"), function(e) {
onEachLazy(e.getElementsByClassName("associatedconstant"), func);
var hiddenElems = e.getElementsByClassName("hidden");
var needToggle = false;
var hlength = hiddenElems.length;
for (var i = 0; i < hlength; ++i) {
if (hasClass(hiddenElems[i], "content") === false &&
hasClass(hiddenElems[i], "docblock") === false) {
needToggle = true;
break;
}
}
if (needToggle === true) {
var inner_toggle = newToggle.cloneNode(true);
inner_toggle.onclick = toggleClicked;
e.insertBefore(inner_toggle, e.firstChild);
impl_call(e.previousSibling, inner_toggle, pageId);
}
});
function createToggle(otherMessage, fontSize, extraClass, show) {
var span = document.createElement("span");
span.className = "toggle-label";
if (show) {
span.style.display = "none";
}
if (!otherMessage) {
span.innerHTML = " Expand description";
} else {
span.innerHTML = otherMessage;
}
if (fontSize) {
span.style.fontSize = fontSize;
}
var mainToggle = toggle.cloneNode(true);
mainToggle.appendChild(span);
var wrapper = document.createElement("div");
wrapper.className = "toggle-wrapper";
if (!show) {
addClass(wrapper, "collapsed");
var inner = mainToggle.getElementsByClassName("inner");
if (inner && inner.length > 0) {
inner[0].innerHTML = "+";
}
}
if (extraClass) {
addClass(wrapper, extraClass);
}
wrapper.appendChild(mainToggle);
return wrapper;
}
var showItemDeclarations = getCurrentValue("rustdoc-item-declarations") === "false";
function buildToggleWrapper(e) {
if (hasClass(e, "autohide")) {
var wrap = e.previousElementSibling;
if (wrap && hasClass(wrap, "toggle-wrapper")) {
var inner_toggle = wrap.childNodes[0];
var extra = e.childNodes[0].tagName === "H3";
e.style.display = "none";
addClass(wrap, "collapsed");
onEachLazy(inner_toggle.getElementsByClassName("inner"), function(e) {
e.innerHTML = labelForToggleButton(true);
});
onEachLazy(inner_toggle.getElementsByClassName("toggle-label"), function(e) {
e.style.display = "inline-block";
if (extra === true) {
i_e.innerHTML = " Show " + e.childNodes[0].innerHTML;
}
});
}
}
if (e.parentNode.id === "main") {
var otherMessage = "";
var fontSize;
var extraClass;
if (hasClass(e, "type-decl")) {
fontSize = "20px";
otherMessage = " Show declaration";
if (showItemDeclarations === false) {
extraClass = "collapsed";
}
} else if (hasClass(e, "sub-variant")) {
otherMessage = " Show fields";
} else if (hasClass(e, "non-exhaustive")) {
otherMessage = " This ";
if (hasClass(e, "non-exhaustive-struct")) {
otherMessage += "struct";
} else if (hasClass(e, "non-exhaustive-enum")) {
otherMessage += "enum";
} else if (hasClass(e, "non-exhaustive-variant")) {
otherMessage += "enum variant";
} else if (hasClass(e, "non-exhaustive-type")) {
otherMessage += "type";
}
otherMessage += " is marked as non-exhaustive";
} else if (hasClass(e.childNodes[0], "impl-items")) {
extraClass = "marg-left";
}
e.parentNode.insertBefore(
createToggle(otherMessage,
fontSize,
extraClass,
hasClass(e, "type-decl") === false || showItemDeclarations === true),
e);
if (hasClass(e, "type-decl") === true && showItemDeclarations === true) {
collapseDocs(e.previousSibling.childNodes[0], "toggle");
}
if (hasClass(e, "non-exhaustive") === true) {
collapseDocs(e.previousSibling.childNodes[0], "toggle");
}
}
}
onEachLazy(document.getElementsByClassName("docblock"), buildToggleWrapper);
onEachLazy(document.getElementsByClassName("sub-variant"), buildToggleWrapper);
function createToggleWrapper(tog) {
var span = document.createElement("span");
span.className = "toggle-label";
span.style.display = "none";
span.innerHTML = " Expand attributes";
tog.appendChild(span);
var wrapper = document.createElement("div");
wrapper.className = "toggle-wrapper toggle-attributes";
wrapper.appendChild(tog);
return wrapper;
}
// To avoid checking on "rustdoc-item-attributes" value on every loop...
var itemAttributesFunc = function() {};
if (getCurrentValue("rustdoc-item-attributes") !== "false") {
itemAttributesFunc = function(x) {
collapseDocs(x.previousSibling.childNodes[0], "toggle");
};
}
var attributesToggle = createToggleWrapper(createSimpleToggle(false));
onEachLazy(main.getElementsByClassName("attributes"), function(i_e) {
var attr_tog = attributesToggle.cloneNode(true);
if (hasClass(i_e, "top-attr") === true) {
addClass(attr_tog, "top-attr");
}
i_e.parentNode.insertBefore(attr_tog, i_e);
itemAttributesFunc(i_e);
});
// To avoid checking on "rustdoc-line-numbers" value on every loop...
var lineNumbersFunc = function() {};
if (getCurrentValue("rustdoc-line-numbers") === "true") {
lineNumbersFunc = function(x) {
var count = x.textContent.split("\n").length;
var elems = [];
for (var i = 0; i < count; ++i) {
elems.push(i + 1);
}
var node = document.createElement("pre");
addClass(node, "line-number");
node.innerHTML = elems.join("\n");
x.parentNode.insertBefore(node, x);
};
}
onEachLazy(document.getElementsByClassName("rust-example-rendered"), function(e) {
if (hasClass(e, "compile_fail")) {
e.addEventListener("mouseover", function(event) {
this.parentElement.previousElementSibling.childNodes[0].style.color = "#f00";
});
e.addEventListener("mouseout", function(event) {
this.parentElement.previousElementSibling.childNodes[0].style.color = "";
});
} else if (hasClass(e, "ignore")) {
e.addEventListener("mouseover", function(event) {
this.parentElement.previousElementSibling.childNodes[0].style.color = "#ff9200";
});
e.addEventListener("mouseout", function(event) {
this.parentElement.previousElementSibling.childNodes[0].style.color = "";
});
}
lineNumbersFunc(e);
});
function showModal(content) {
var modal = document.createElement("div");
modal.id = "important";
addClass(modal, "modal");
modal.innerHTML = "";
document.getElementsByTagName("body")[0].appendChild(modal);
document.getElementById("modal-close").onclick = hideModal;
modal.onclick = hideModal;
}
function hideModal() {
var modal = document.getElementById("important");
if (modal) {
modal.parentNode.removeChild(modal);
}
}
onEachLazy(document.getElementsByClassName("important-traits"), function(e) {
e.onclick = function() {
showModal(e.lastElementChild.innerHTML);
};
});
// In the search display, allows to switch between tabs.
function printTab(nb) {
if (nb === 0 || nb === 1 || nb === 2) {
currentTab = nb;
}
var nb_copy = nb;
onEachLazy(document.getElementById("titles").childNodes, function(elem) {
if (nb_copy === 0) {
addClass(elem, "selected");
} else {
removeClass(elem, "selected");
}
nb_copy -= 1;
});
onEachLazy(document.getElementById("results").childNodes, function(elem) {
if (nb === 0) {
elem.style.display = "";
} else {
elem.style.display = "none";
}
nb -= 1;
});
}
function putBackSearch(search_input) {
if (search_input.value !== "") {
addClass(main, "hidden");
removeClass(document.getElementById("search"), "hidden");
if (browserSupportsHistoryApi()) {
history.replaceState(search_input.value,
"",
"?search=" + encodeURIComponent(search_input.value));
}
}
}
if (search_input) {
search_input.onfocus = function() {
putBackSearch(this);
};
}
var params = getQueryStringParams();
if (params && params.search) {
addClass(main, "hidden");
var search = document.getElementById("search");
removeClass(search, "hidden");
search.innerHTML = "Loading search results...
";
}
var sidebar_menu = document.getElementsByClassName("sidebar-menu")[0];
if (sidebar_menu) {
sidebar_menu.onclick = function() {
var sidebar = document.getElementsByClassName("sidebar")[0];
if (hasClass(sidebar, "mobile") === true) {
hideSidebar();
} else {
showSidebar();
}
};
}
window.onresize = function() {
hideSidebar();
};
autoCollapse(getPageId(), getCurrentValue("rustdoc-collapse") === "true");
if (window.location.hash && window.location.hash.length > 0) {
expandSection(window.location.hash.replace(/^#/, ""));
}
if (main) {
onEachLazy(main.getElementsByClassName("loading-content"), function(e) {
e.remove();
});
onEachLazy(main.childNodes, function(e) {
// Unhide the actual content once loading is complete. Headers get
// flex treatment for their horizontal layout, divs get block treatment
// for vertical layout (column-oriented flex layout for divs caused
// errors in mobile browsers).
if (e.tagName === "H2" || e.tagName === "H3") {
var nextTagName = e.nextElementSibling.tagName;
if (nextTagName == "H2" || nextTagName == "H3") {
e.nextElementSibling.style.display = "flex";
} else {
e.nextElementSibling.style.display = "block";
}
}
});
}
function addSearchOptions(crates) {
var elem = document.getElementById('crate-search');
if (!elem) {
return;
}
var crates_text = [];
if (Object.keys(crates).length > 1) {
for (var crate in crates) {
if (crates.hasOwnProperty(crate)) {
crates_text.push(crate);
}
}
}
crates_text.sort(function(a, b) {
var lower_a = a.toLowerCase();
var lower_b = b.toLowerCase();
if (lower_a < lower_b) {
return -1;
} else if (lower_a > lower_b) {
return 1;
}
return 0;
});
for (var i = 0; i < crates_text.length; ++i) {
var option = document.createElement("option");
option.value = crates_text[i];
option.innerText = crates_text[i];
elem.appendChild(option);
}
}
window.addSearchOptions = addSearchOptions;
}());
// Sets the focus on the search bar at the top of the page
function focusSearchBar() {
document.getElementsByClassName("search-input")[0].focus();
}
// Removes the focus from the search bar
function defocusSearchBar() {
document.getElementsByClassName("search-input")[0].blur();
}