Skip to content

Commit

Permalink
deploy: da70d7a
Browse files Browse the repository at this point in the history
  • Loading branch information
damirka committed Mar 22, 2024
1 parent 5790e24 commit cd48e0b
Show file tree
Hide file tree
Showing 1,431 changed files with 12,731 additions and 151,377 deletions.
2 changes: 1 addition & 1 deletion .nojekyll
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This file makes sure that Github Pages doesn't process mdBook's output.
This file makes sure that Github Pages doesn't process mdBook's output.
219 changes: 219 additions & 0 deletions 404.html

Large diffs are not rendered by default.

251 changes: 11 additions & 240 deletions advanced-topics/index.html

Large diffs are not rendered by default.

400 changes: 0 additions & 400 deletions advanced-topics/managing-collections-with-vectors.html

This file was deleted.

508 changes: 11 additions & 497 deletions advanced-topics/ownership-and-references.html

Large diffs are not rendered by default.

456 changes: 11 additions & 445 deletions advanced-topics/struct.html

Large diffs are not rendered by default.

367 changes: 0 additions & 367 deletions advanced-topics/types-with-abilities.html

This file was deleted.

512 changes: 11 additions & 501 deletions advanced-topics/understanding-generics.html

Large diffs are not rendered by default.

227 changes: 227 additions & 0 deletions appendix/contributing.html

Large diffs are not rendered by default.

244 changes: 244 additions & 0 deletions appendix/glossary.html

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion ayu-highlight.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Original by Dempfi (https://github.com/dempfi/ayu)
overflow-x: auto;
background: #191f26;
color: #e6e1cf;
padding: 0.5em;
}

.hljs-comment,
Expand Down Expand Up @@ -77,3 +76,13 @@ Original by Dempfi (https://github.com/dempfi/ayu)
.hljs-deletion {
color: #d96c75;
}

/* Custom */

.hljs.language-undefined {
font-weight: 400;
line-height: inherit;
font-size: inherit;
font-family: inherit;
background: none;
}
278 changes: 278 additions & 0 deletions basic-syntax/address.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

35 changes: 14 additions & 21 deletions sui/basic-syntax/comments.html → basic-syntax/comments.html

Large diffs are not rendered by default.

285 changes: 285 additions & 0 deletions basic-syntax/constants.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

251 changes: 251 additions & 0 deletions basic-syntax/copy-ability.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

45 changes: 19 additions & 26 deletions sui/basic-syntax/expression.html → basic-syntax/expression.html

Large diffs are not rendered by default.

39 changes: 16 additions & 23 deletions sui/basic-syntax/function.html → basic-syntax/function.html

Large diffs are not rendered by default.

35 changes: 14 additions & 21 deletions sui/basic-syntax/generics.html → basic-syntax/generics.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

233 changes: 233 additions & 0 deletions basic-syntax/index.html

Large diffs are not rendered by default.

42 changes: 16 additions & 26 deletions sui/basic-syntax/module.html → basic-syntax/module.html

Large diffs are not rendered by default.

39 changes: 16 additions & 23 deletions sui/basic-syntax/option.html → basic-syntax/option.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

35 changes: 14 additions & 21 deletions sui/basic-syntax/references.html → basic-syntax/references.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

51 changes: 22 additions & 29 deletions sui/basic-syntax/string.html → basic-syntax/string.html

Large diffs are not rendered by default.

Large diffs are not rendered by default.

62 changes: 37 additions & 25 deletions sui/basic-syntax/struct.html → basic-syntax/struct.html

Large diffs are not rendered by default.

270 changes: 270 additions & 0 deletions basic-syntax/type-reflection.html

Large diffs are not rendered by default.

35 changes: 14 additions & 21 deletions sui/basic-syntax/vector.html → basic-syntax/vector.html

Large diffs are not rendered by default.

289 changes: 289 additions & 0 deletions basic-syntax/visibility.html

Large diffs are not rendered by default.

258 changes: 258 additions & 0 deletions before-we-begin/ide-support.html

Large diffs are not rendered by default.

233 changes: 233 additions & 0 deletions before-we-begin/index.html

Large diffs are not rendered by default.

245 changes: 245 additions & 0 deletions before-we-begin/install-sui.html

Large diffs are not rendered by default.

234 changes: 234 additions & 0 deletions before-we-begin/move-2024.html

Large diffs are not rendered by default.

136 changes: 86 additions & 50 deletions book.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
window.onunload = function () { };

// Global variable, shared between modules
function playpen_text(playpen) {
let code_block = playpen.querySelector("code");
function playground_text(playground, hidden = true) {
let code_block = playground.querySelector("code");

if (window.ace && code_block.classList.contains("editable")) {
let editor = window.ace.edit(code_block);
return editor.getValue();
} else {
} else if (hidden) {
return code_block.textContent;
} else {
return code_block.innerText;
}
}

Expand All @@ -23,8 +25,8 @@ function playpen_text(playpen) {
]);
}

var playpens = Array.from(document.querySelectorAll(".playpen"));
if (playpens.length > 0) {
var playgrounds = Array.from(document.querySelectorAll(".playground"));
if (playgrounds.length > 0) {
fetch_with_timeout("https://play.rust-lang.org/meta/crates", {
headers: {
'Content-Type': "application/json",
Expand All @@ -36,21 +38,21 @@ function playpen_text(playpen) {
.then(response => {
// get list of crates available in the rust playground
let playground_crates = response.crates.map(item => item["id"]);
playpens.forEach(block => handle_crate_list_update(block, playground_crates));
playgrounds.forEach(block => handle_crate_list_update(block, playground_crates));
});
}

function handle_crate_list_update(playpen_block, playground_crates) {
function handle_crate_list_update(playground_block, playground_crates) {
// update the play buttons after receiving the response
update_play_button(playpen_block, playground_crates);
update_play_button(playground_block, playground_crates);

// and install on change listener to dynamically update ACE editors
if (window.ace) {
let code_block = playpen_block.querySelector("code");
let code_block = playground_block.querySelector("code");
if (code_block.classList.contains("editable")) {
let editor = window.ace.edit(code_block);
editor.addEventListener("change", function (e) {
update_play_button(playpen_block, playground_crates);
update_play_button(playground_block, playground_crates);
});
// add Ctrl-Enter command to execute rust code
editor.commands.addCommand({
Expand All @@ -59,14 +61,14 @@ function playpen_text(playpen) {
win: "Ctrl-Enter",
mac: "Ctrl-Enter"
},
exec: _editor => run_rust_code(playpen_block)
exec: _editor => run_rust_code(playground_block)
});
}
}
}

// updates the visibility of play button based on `no_run` class and
// used crates vs ones available on http://play.rust-lang.org
// used crates vs ones available on https://play.rust-lang.org
function update_play_button(pre_block, playground_crates) {
var play_button = pre_block.querySelector(".play-button");

Expand All @@ -77,7 +79,7 @@ function playpen_text(playpen) {
}

// get list of `extern crate`'s from snippet
var txt = playpen_text(pre_block);
var txt = playground_text(pre_block);
var re = /extern\s+crate\s+([a-zA-Z_0-9]+)\s*;/g;
var snippet_crates = [];
var item;
Expand Down Expand Up @@ -106,11 +108,14 @@ function playpen_text(playpen) {
code_block.append(result_block);
}

let text = playpen_text(code_block);
let text = playground_text(code_block);
let classes = code_block.querySelector('code').classList;
let has_2018 = classes.contains("edition2018");
let edition = has_2018 ? "2018" : "2015";

let edition = "2015";
if(classes.contains("edition2018")) {
edition = "2018";
} else if(classes.contains("edition2021")) {
edition = "2021";
}
var params = {
version: "stable",
optimize: "0",
Expand All @@ -133,7 +138,15 @@ function playpen_text(playpen) {
body: JSON.stringify(params)
})
.then(response => response.json())
.then(response => result_block.innerText = response.result)
.then(response => {
if (response.result.trim() === '') {
result_block.innerText = "No output";
result_block.classList.add("result-no-output");
} else {
result_block.innerText = response.result;
result_block.classList.remove("result-no-output");
}
})
.catch(error => result_block.innerText = "Playground Communication: " + error.message);
}

Expand All @@ -151,12 +164,12 @@ function playpen_text(playpen) {
if (window.ace) {
// language-rust class needs to be removed for editable
// blocks or highlightjs will capture events
Array
.from(document.querySelectorAll('code.editable'))
code_nodes
.filter(function (node) {return node.classList.contains("editable"); })
.forEach(function (block) { block.classList.remove('language-rust'); });

Array
.from(document.querySelectorAll('code:not(.editable)'))
code_nodes
.filter(function (node) {return !node.classList.contains("editable"); })
.forEach(function (block) { hljs.highlightBlock(block); });
} else {
code_nodes.forEach(function (block) { hljs.highlightBlock(block); });
Expand All @@ -166,7 +179,7 @@ function playpen_text(playpen) {
// even if highlighting doesn't apply
code_nodes.forEach(function (block) { block.classList.add('hljs'); });

Array.from(document.querySelectorAll("code.language-rust")).forEach(function (block) {
Array.from(document.querySelectorAll("code.hljs")).forEach(function (block) {

var lines = Array.from(block.querySelectorAll('.boring'));
// If no lines were hidden, return
Expand All @@ -175,23 +188,23 @@ function playpen_text(playpen) {

var buttons = document.createElement('div');
buttons.className = 'buttons';
buttons.innerHTML = "<button class=\"fa fa-expand\" title=\"Show hidden lines\" aria-label=\"Show hidden lines\"></button>";
buttons.innerHTML = "<button class=\"fa fa-eye\" title=\"Show hidden lines\" aria-label=\"Show hidden lines\"></button>";

// add expand button
var pre_block = block.parentNode;
pre_block.insertBefore(buttons, pre_block.firstChild);

pre_block.querySelector('.buttons').addEventListener('click', function (e) {
if (e.target.classList.contains('fa-expand')) {
e.target.classList.remove('fa-expand');
e.target.classList.add('fa-compress');
if (e.target.classList.contains('fa-eye')) {
e.target.classList.remove('fa-eye');
e.target.classList.add('fa-eye-slash');
e.target.title = 'Hide lines';
e.target.setAttribute('aria-label', e.target.title);

block.classList.remove('hide-boring');
} else if (e.target.classList.contains('fa-compress')) {
e.target.classList.remove('fa-compress');
e.target.classList.add('fa-expand');
} else if (e.target.classList.contains('fa-eye-slash')) {
e.target.classList.remove('fa-eye-slash');
e.target.classList.add('fa-eye');
e.target.title = 'Show hidden lines';
e.target.setAttribute('aria-label', e.target.title);

Expand All @@ -200,10 +213,10 @@ function playpen_text(playpen) {
});
});

if (window.playpen_copyable) {
if (window.playground_copyable) {
Array.from(document.querySelectorAll('pre code')).forEach(function (block) {
var pre_block = block.parentNode;
if (!pre_block.classList.contains('playpen')) {
if (!pre_block.classList.contains('playground')) {
var buttons = pre_block.querySelector(".buttons");
if (!buttons) {
buttons = document.createElement('div');
Expand All @@ -222,8 +235,8 @@ function playpen_text(playpen) {
});
}

// Process playpen code blocks
Array.from(document.querySelectorAll(".playpen")).forEach(function (pre_block) {
// Process playground code blocks
Array.from(document.querySelectorAll(".playground")).forEach(function (pre_block) {
// Add play button
var buttons = pre_block.querySelector(".buttons");
if (!buttons) {
Expand All @@ -243,7 +256,7 @@ function playpen_text(playpen) {
run_rust_code(pre_block);
});

if (window.playpen_copyable) {
if (window.playground_copyable) {
var copyCodeClipboardButton = document.createElement('button');
copyCodeClipboardButton.className = 'fa fa-copy clip-button';
copyCodeClipboardButton.innerHTML = '<i class="tooltiptext"></i>';
Expand Down Expand Up @@ -288,6 +301,13 @@ function playpen_text(playpen) {
themePopup.querySelector("button#" + get_theme()).focus();
}

function updateThemeSelected() {
themePopup.querySelectorAll('.theme-selected').forEach(function (el) {
el.classList.remove('theme-selected');
});
themePopup.querySelector("button#" + get_theme()).classList.add('theme-selected');
}

function hideThemes() {
themePopup.style.display = 'none';
themeToggleButton.setAttribute('aria-expanded', false);
Expand Down Expand Up @@ -326,7 +346,7 @@ function playpen_text(playpen) {
}

setTimeout(function () {
themeColorMetaTag.content = getComputedStyle(document.body).backgroundColor;
themeColorMetaTag.content = getComputedStyle(document.documentElement).backgroundColor;
}, 1);

if (window.ace && window.editors) {
Expand All @@ -343,6 +363,7 @@ function playpen_text(playpen) {

html.classList.remove(previousTheme);
html.classList.add(theme);
updateThemeSelected();
}

// Set theme
Expand All @@ -359,7 +380,14 @@ function playpen_text(playpen) {
});

themePopup.addEventListener('click', function (e) {
var theme = e.target.id || e.target.parentElement.id;
var theme;
if (e.target.className === "theme") {
theme = e.target.id;
} else if (e.target.parentElement.className === "theme") {
theme = e.target.parentElement.id;
} else {
return;
}
set_theme(theme);
});

Expand Down Expand Up @@ -456,6 +484,11 @@ function playpen_text(playpen) {
// Toggle sidebar
sidebarToggleButton.addEventListener('click', function sidebarToggle() {
if (html.classList.contains("sidebar-hidden")) {
var current_width = parseInt(
document.documentElement.style.getPropertyValue('--sidebar-width'), 10);
if (current_width < 150) {
document.documentElement.style.setProperty('--sidebar-width', '150px');
}
showSidebar();
} else if (html.classList.contains("sidebar-visible")) {
hideSidebar();
Expand All @@ -476,7 +509,16 @@ function playpen_text(playpen) {
html.classList.add('sidebar-resizing');
}
function resize(e) {
document.documentElement.style.setProperty('--sidebar-width', (e.clientX - sidebar.offsetLeft) + 'px');
var pos = (e.clientX - sidebar.offsetLeft);
if (pos < 20) {
hideSidebar();
} else {
if (html.classList.contains("sidebar-hidden")) {
showSidebar();
}
pos = Math.min(pos, window.innerWidth - 100);
document.documentElement.style.setProperty('--sidebar-width', pos + 'px');
}
}
//on mouseup remove windows functions mousemove & mouseup
function stopResize(e) {
Expand Down Expand Up @@ -509,13 +551,6 @@ function playpen_text(playpen) {
firstContact = null;
}
}, { passive: true });

// Scroll sidebar to current active section
var activeSection = document.getElementById("sidebar").querySelector(".active");
if (activeSection) {
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
activeSection.scrollIntoView({ block: 'center' });
}
})();

(function chapterNavigation() {
Expand Down Expand Up @@ -558,8 +593,8 @@ function playpen_text(playpen) {
var clipboardSnippets = new ClipboardJS('.clip-button', {
text: function (trigger) {
hideTooltip(trigger);
let playpen = trigger.closest("pre");
return playpen_text(playpen);
let playground = trigger.closest("pre");
return playground_text(playground, false);
}
});

Expand Down Expand Up @@ -634,13 +669,14 @@ function playpen_text(playpen) {
}, { passive: true });
})();
(function controllBorder() {
menu.classList.remove('bordered');
document.addEventListener('scroll', function () {
function updateBorder() {
if (menu.offsetTop === 0) {
menu.classList.remove('bordered');
} else {
menu.classList.add('bordered');
}
}, { passive: true });
}
updateBorder();
document.addEventListener('scroll', updateBorder, { passive: true });
})();
})();
1 change: 0 additions & 1 deletion cn/.nojekyll

This file was deleted.

4 changes: 0 additions & 4 deletions cn/FontAwesome/css/font-awesome.css

This file was deleted.

Binary file removed cn/FontAwesome/fonts/FontAwesome.ttf
Binary file not shown.
Binary file removed cn/FontAwesome/fonts/fontawesome-webfont.eot
Binary file not shown.
Loading

0 comments on commit cd48e0b

Please sign in to comment.