mirror of https://github.com/sunface/rust-course
commit
8262341177
After Width: | Height: | Size: 99 KiB |
File diff suppressed because one or more lines are too long
@ -0,0 +1,158 @@
|
|||||||
|
var initAll = function () {
|
||||||
|
var path = window.location.pathname;
|
||||||
|
if (path.endsWith("/print.html")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var images = document.querySelectorAll("main img")
|
||||||
|
Array.prototype.forEach.call(images, function (img) {
|
||||||
|
img.addEventListener("click", function () {
|
||||||
|
BigPicture({
|
||||||
|
el: img,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Un-active everything when you click it
|
||||||
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
|
||||||
|
el.addEventHandler("click", function () {
|
||||||
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
|
||||||
|
el.classList.remove("active");
|
||||||
|
});
|
||||||
|
el.classList.add("active");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var updateFunction = function () {
|
||||||
|
var id = null;
|
||||||
|
var elements = document.getElementsByClassName("header");
|
||||||
|
Array.prototype.forEach.call(elements, function (el) {
|
||||||
|
if (window.pageYOffset >= el.offsetTop) {
|
||||||
|
id = el;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
|
||||||
|
el.classList.remove("active");
|
||||||
|
});
|
||||||
|
|
||||||
|
Array.prototype.forEach.call(document.getElementsByClassName("pagetoc")[0].children, function (el) {
|
||||||
|
if (id == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (id.href.localeCompare(el.href) == 0) {
|
||||||
|
el.classList.add("active");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var pagetoc = document.getElementsByClassName("pagetoc")[0];
|
||||||
|
var elements = document.getElementsByClassName("header");
|
||||||
|
Array.prototype.forEach.call(elements, function (el) {
|
||||||
|
var link = document.createElement("a");
|
||||||
|
|
||||||
|
// Indent shows hierarchy
|
||||||
|
var indent = "";
|
||||||
|
switch (el.parentElement.tagName) {
|
||||||
|
case "H1":
|
||||||
|
return;
|
||||||
|
case "H3":
|
||||||
|
indent = "20px";
|
||||||
|
break;
|
||||||
|
case "H4":
|
||||||
|
indent = "40px";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
link.appendChild(document.createTextNode(el.text));
|
||||||
|
link.style.paddingLeft = indent;
|
||||||
|
link.href = el.href;
|
||||||
|
pagetoc.appendChild(link);
|
||||||
|
});
|
||||||
|
updateFunction.call();
|
||||||
|
|
||||||
|
// Handle active elements on scroll
|
||||||
|
window.addEventListener("scroll", updateFunction);
|
||||||
|
|
||||||
|
document.getElementById("theme-list").addEventListener("click", function (e) {
|
||||||
|
var iframe = document.querySelector('.giscus-frame');
|
||||||
|
if (!iframe) return;
|
||||||
|
var theme;
|
||||||
|
if (e.target.className === "theme") {
|
||||||
|
theme = e.target.id;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 若当前 mdbook 主题不是 Light 或 Rust ,则将 giscuz 主题设置为 transparent_dark
|
||||||
|
var giscusTheme = "light"
|
||||||
|
if (theme != "light" && theme != "rust") {
|
||||||
|
giscusTheme = "transparent_dark";
|
||||||
|
}
|
||||||
|
|
||||||
|
var msg = {
|
||||||
|
setConfig: {
|
||||||
|
theme: giscusTheme
|
||||||
|
}
|
||||||
|
};
|
||||||
|
iframe.contentWindow.postMessage({ giscus: msg }, 'https://giscus.app');
|
||||||
|
});
|
||||||
|
|
||||||
|
pagePath = pagePath.replace("index.md", "");
|
||||||
|
pagePath = pagePath.replace(".md", "");
|
||||||
|
if (pagePath.length > 0) {
|
||||||
|
if (pagePath.charAt(pagePath.length-1) == "/"){
|
||||||
|
pagePath = pagePath.substring(0, pagePath.length-1)
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
pagePath = "index"
|
||||||
|
}
|
||||||
|
|
||||||
|
// add vistors count
|
||||||
|
var ele = document.createElement("div");
|
||||||
|
ele.setAttribute("align","center");
|
||||||
|
var count = document.createElement("img")
|
||||||
|
count.setAttribute("src", "https://visitor-badge.glitch.me/badge?page_id=" + path);
|
||||||
|
ele.appendChild(count);
|
||||||
|
var divider =document.createElement("hr")
|
||||||
|
|
||||||
|
document.getElementById("giscus-container").appendChild(ele);
|
||||||
|
document.getElementById("giscus-container").appendChild(divider);
|
||||||
|
|
||||||
|
// 选取浏览器默认使用的语言
|
||||||
|
// const lang = navigator.language || navigator.userLanguage
|
||||||
|
|
||||||
|
// 若当前 mdbook 主题为 Light 或 Rust ,则将 giscuz 主题设置为 light
|
||||||
|
var theme = "transparent_dark";
|
||||||
|
const themeClass = document.getElementsByTagName("html")[0].className;
|
||||||
|
if (themeClass.indexOf("light") != -1 || themeClass.indexOf("rust") != -1) {
|
||||||
|
theme = "light"
|
||||||
|
}
|
||||||
|
|
||||||
|
var script = document.createElement("script")
|
||||||
|
script.type = "text/javascript";
|
||||||
|
script.src = "https://giscus.app/client.js";
|
||||||
|
script.async = true;
|
||||||
|
script.crossOrigin = "anonymous";
|
||||||
|
script.setAttribute("data-repo", "sunface/rust-course");
|
||||||
|
script.setAttribute("data-repo-id", "MDEwOlJlcG9zaXRvcnkxNDM4MjIwNjk=");
|
||||||
|
script.setAttribute("data-category", "章节评论区");
|
||||||
|
script.setAttribute("data-category-id", "DIC_kwDOCJKM9c4COQcP");
|
||||||
|
script.setAttribute("data-mapping", "specific");
|
||||||
|
script.setAttribute("data-term", pagePath);
|
||||||
|
script.setAttribute("data-reactions-enabled", "1");
|
||||||
|
script.setAttribute("data-emit-metadata", "0");
|
||||||
|
script.setAttribute("data-input-position", "top");
|
||||||
|
script.setAttribute("data-theme", theme);
|
||||||
|
// script.setAttribute("data-lang", lang);
|
||||||
|
// 预先加载评论会更好,这样用户读到那边时,评论就加载好了
|
||||||
|
// script.setAttribute("data-loading", "lazy");
|
||||||
|
document.getElementById("giscus-container").appendChild(script);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('load', initAll);
|
@ -1,33 +0,0 @@
|
|||||||
body.light .does_not_compile,
|
|
||||||
body.light .panics,
|
|
||||||
body.light .not_desired_behavior,
|
|
||||||
body.rust .does_not_compile,
|
|
||||||
body.rust .panics,
|
|
||||||
body.rust .not_desired_behavior {
|
|
||||||
background: #fff1f1;
|
|
||||||
}
|
|
||||||
|
|
||||||
body.coal .does_not_compile,
|
|
||||||
body.coal .panics,
|
|
||||||
body.coal .not_desired_behavior,
|
|
||||||
body.navy .does_not_compile,
|
|
||||||
body.navy .panics,
|
|
||||||
body.navy .not_desired_behavior,
|
|
||||||
body.ayu .does_not_compile,
|
|
||||||
body.ayu .panics,
|
|
||||||
body.ayu .not_desired_behavior {
|
|
||||||
background: #501f21;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ferris {
|
|
||||||
position: absolute;
|
|
||||||
z-index: 99;
|
|
||||||
right: 5px;
|
|
||||||
top: 30px;
|
|
||||||
width: 10%;
|
|
||||||
height: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ferris-explain {
|
|
||||||
width: 100px;
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
var ferrisTypes = [
|
|
||||||
{
|
|
||||||
attr: 'does_not_compile',
|
|
||||||
title: 'This code does not compile!'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attr: 'panics',
|
|
||||||
title: 'This code panics!'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attr: 'unsafe',
|
|
||||||
title: 'This code block contains unsafe code.'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attr: 'not_desired_behavior',
|
|
||||||
title: 'This code does not produce the desired behavior.'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
for (var ferrisType of ferrisTypes) {
|
|
||||||
attachFerrises(ferrisType)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function attachFerrises (type) {
|
|
||||||
var elements = document.getElementsByClassName(type.attr)
|
|
||||||
|
|
||||||
for (var codeBlock of elements) {
|
|
||||||
var lines = codeBlock.textContent.split(/\r|\r\n|\n/).length - 1;
|
|
||||||
|
|
||||||
if (lines >= 4) {
|
|
||||||
attachFerris(codeBlock, type)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function attachFerris (element, type) {
|
|
||||||
var a = document.createElement('a')
|
|
||||||
a.setAttribute('href', 'ch00-00-introduction.html#ferris')
|
|
||||||
a.setAttribute('target', '_blank')
|
|
||||||
|
|
||||||
var img = document.createElement('img')
|
|
||||||
img.setAttribute('src', '/img/ferris/' + type.attr + '.svg')
|
|
||||||
img.setAttribute('title', type.title)
|
|
||||||
img.className = 'ferris'
|
|
||||||
|
|
||||||
a.appendChild(img)
|
|
||||||
|
|
||||||
element.parentElement.insertBefore(a, element)
|
|
||||||
}
|
|
After Width: | Height: | Size: 127 KiB |
@ -1,9 +0,0 @@
|
|||||||
span.caption {
|
|
||||||
font-size: .8em;
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.caption code {
|
|
||||||
font-size: 0.875em;
|
|
||||||
font-weight: 400;
|
|
||||||
}
|
|
After Width: | Height: | Size: 46 KiB |
@ -0,0 +1 @@
|
|||||||
|
# 裸指针、引用和智能指针 todo
|
@ -0,0 +1,5 @@
|
|||||||
|
# 异步编程
|
||||||
|
|
||||||
|
接下来,我们将深入了解 async/await 的使用方式及背后的原理。
|
||||||
|
|
||||||
|
> 本章在内容上大量借鉴和翻译了原版英文书籍[Asynchronous Programming In Rust](https://rust-lang.github.io/async-book/01_getting_started/01_chapter.html), 特此感谢
|
@ -0,0 +1,11 @@
|
|||||||
|
# Rust 异步编程
|
||||||
|
在艰难的学完 Rust 入门和进阶所有的 70 个章节后,我们终于来到了这里。假如之前攀登的是珠穆朗玛峰,那么现在攀登的就是乔戈里峰( 比珠峰还难攀爬... )。
|
||||||
|
|
||||||
|
如果你想开发 Web 服务器、数据库驱动、消息服务等需要高并发的服务,那么本章的内容将值得认真对待和学习,将从以下方面深入讲解 Rust 的异步编程:
|
||||||
|
|
||||||
|
- Rust 异步编程的通用概念介绍
|
||||||
|
- Future 以及异步任务调度
|
||||||
|
- async/await 和 Pin/Unpin
|
||||||
|
- 异步编程常用的三方库
|
||||||
|
- tokio 库
|
||||||
|
- 一些示例
|
@ -1,14 +0,0 @@
|
|||||||
# 异步编程
|
|
||||||
|
|
||||||
在艰难的学完 Rust 入门和进阶所有的 55 个章节后,我们终于来到了这里。假如之前攀登的是珠穆拉玛峰,那么现在攀登的就是乔戈里峰( 比珠峰还难攀爬... ),本章将学习的内容是关于 async 异步编程。
|
|
||||||
|
|
||||||
如果你想开发 Web 服务器、数据库驱动、消息服务等需要高并发的服务,那么本章的内容将值得认真对待和学习,将从以下方面深入讲解 Rust 的异步编程:
|
|
||||||
|
|
||||||
- Rust 异步编程的通用概念介绍
|
|
||||||
- Future 以及异步任务调度
|
|
||||||
- async/await 和 Pin/Unpin
|
|
||||||
- 异步编程常用的三方库
|
|
||||||
- tokio 库
|
|
||||||
- 一些示例
|
|
||||||
|
|
||||||
> 本章在内容上大量借鉴和翻译了原版英文书籍[Asynchronous Programming In Rust](https://rust-lang.github.io/async-book/01_getting_started/01_chapter.html), 特此感谢
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue