// Populate the sidebar
//
// This is a script, and not included directly in the page, to control the total size of the book.
// The TOC contains an entry for each page, so if each page includes a copy of the TOC,
// the total size of the page becomes O(n**2).
class MDBookSidebarScrollbox extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
this.innerHTML = '
- 1. Rust By Practice
- 2. Small projects with Elegant code
- 3. Variables
- 4. Basic Types
❱
- 4.1. Numbers
- 4.2. Char, Bool and Unit
- 4.3. Statements and Expressions
- 4.4. Functions
- 5. Ownership and Borrowing
❱
- 5.1. Ownership
- 5.2. Reference and Borrowing
- 6. Compound Types
❱
- 6.1. string
- 6.2. Array
- 6.3. Slice
- 6.4. Tuple
- 6.5. Struct
- 6.6. Enum
- 7. Flow Control
- 8. Pattern Match
❱
- 8.1. match, matches! and if let
- 8.2. Patterns
- 9. Method & Associated function
- 10. Generics and Traits
❱
- 10.1. Generics
- 10.2. Const Generics
- 10.3. Traits
- 10.4. Trait Object
- 10.5. Advanced Traits
- 11. Collection Types
❱
- 11.1. String
- 11.2. Vector
- 11.3. HashMap
- 12. Type Conversion
❱
- 12.1. as
- 12.2. From/Into
- 12.3. Others
- 13. Result and panic
❱
- 13.1. panic!
- 13.2. Result and ?
- 14. Crate and Module
❱
- 14.1. Package and Crate
- 14.2. Module
- 14.3. Advanced use and pub
- 15. Comments and Docs
- 16. Formatted output
❱
- 16.1. println! and format!
- 16.2. Debug and Display
- 16.3. formating
- 17. Lifetime
❱
- 17.1. basic
- 17.2. &'static and T: 'static
- 17.3. advanced
- 18. Functional programing
❱
- 18.1. Closure
- 18.2. Iterator
- 19. newtype and DST
- 20. Smart pointers TODO
❱
- 20.1. Box
- 20.2. Deref
- 20.3. Drop
- 20.4. Rc and Arc
- 20.5. Cell and RefCell
- 21. Weak and Circle reference TODO
- 22. Self referential TODO
- 23. Threads TODO
❱
- 23.1. Basic using
- 23.2. Message passing
- 23.3. Sync
- 23.4. Atomic
- 23.5. Send and Sync
- 24. Global variables TODO
- 25. Errors TODO
- 26. Unsafe doing
❱
- 26.1. Inline assembly
- 27. Macro TODO
- 28. Tests TODO
❱
- 28.1. Write Tests
- 28.2. Benchmark
- 28.3. Unit and Integration
- 28.4. Assertions
- 29. Async/Await TODO
❱
- 29.1. async and await!
- 29.2. Future
- 29.3. Pin and Unpin
- 29.4. Stream
- 30. Standard Library TODO
❱
- 30.1. String
- 31. Fighting with Compiler
❱
- 31.1. Borrowing
';
// Set the current, active page, and reveal it if it's hidden
let current_page = document.location.href.toString().split("#")[0];
if (current_page.endsWith("/")) {
current_page += "index.html";
}
var links = Array.prototype.slice.call(this.querySelectorAll("a"));
var l = links.length;
for (var i = 0; i < l; ++i) {
var link = links[i];
var href = link.getAttribute("href");
if (href && !href.startsWith("#") && !/^(?:[a-z+]+:)?\/\//.test(href)) {
link.href = path_to_root + href;
}
// The "index" page is supposed to alias the first chapter in the book.
if (link.href === current_page || (i === 0 && path_to_root === "" && current_page.endsWith("/index.html"))) {
link.classList.add("active");
var parent = link.parentElement;
if (parent && parent.classList.contains("chapter-item")) {
parent.classList.add("expanded");
}
while (parent) {
if (parent.tagName === "LI" && parent.previousElementSibling) {
if (parent.previousElementSibling.classList.contains("chapter-item")) {
parent.previousElementSibling.classList.add("expanded");
}
}
parent = parent.parentElement;
}
}
}
// Track and set sidebar scroll position
this.addEventListener('click', function(e) {
if (e.target.tagName === 'A') {
sessionStorage.setItem('sidebar-scroll', this.scrollTop);
}
}, { passive: true });
var sidebarScrollTop = sessionStorage.getItem('sidebar-scroll');
sessionStorage.removeItem('sidebar-scroll');
if (sidebarScrollTop) {
// preserve sidebar scroll position when navigating via links within sidebar
this.scrollTop = sidebarScrollTop;
} else {
// scroll sidebar to current active section when navigating via "next/previous chapter" buttons
var activeSection = document.querySelector('#sidebar .active');
if (activeSection) {
activeSection.scrollIntoView({ block: 'center' });
}
}
// Toggle buttons
var sidebarAnchorToggles = document.querySelectorAll('#sidebar a.toggle');
function toggleSection(ev) {
ev.currentTarget.parentElement.classList.toggle('expanded');
}
Array.from(sidebarAnchorToggles).forEach(function (el) {
el.addEventListener('click', toggleSection);
});
}
}
window.customElements.define("mdbook-sidebar-scrollbox", MDBookSidebarScrollbox);