Skip to content

Commit 4ecf143

Browse files
committed
doc: cleanup of doc/index.md
- Add quick link to API docs - Add marker for external links, to help offline users - Add information about using 'cargo doc' and the playground - Clean up some of the wording - Update body & header style to match rustdoc defaults
1 parent 07c993e commit 4ecf143

File tree

1 file changed

+165
-63
lines changed

1 file changed

+165
-63
lines changed

src/doc/index.md

+165-63
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44
nav {
55
display: none;
66
}
7+
body {
8+
font-family: serif;
9+
}
10+
h1, h2, h3, h4, h5, h6 {
11+
font-family: sans-serif;
12+
}
13+
h3 {
14+
font-size: 1.35rem;
15+
}
16+
h4 {
17+
font-size: 1.1rem;
18+
}
19+
20+
/* Formatting for docs search bar */
721
#search-input {
822
width: calc(100% - 58px);
923
}
@@ -21,53 +35,74 @@ nav {
2135
#search-but:hover, #search-input:focus {
2236
border-color: #55a9ff;
2337
}
24-
h2 {
25-
font-size: 18px;
38+
39+
/* Formatting for external link icon */
40+
svg.external-link {
41+
display: inline-block;
42+
position: relative;
43+
vertical-align: super;
44+
width: 0.7rem;
45+
height: 0.7rem;
46+
padding-left: 2px;
47+
top: 3px;
2648
}
2749
</style>
2850

29-
Welcome to an overview of the documentation provided by the [Rust project].
30-
All of these projects are managed by the Docs Team; there are other
31-
unofficial documentation resources as well!
51+
Welcome to an overview of the documentation provided by the [Rust
52+
project]. This page contains links to various helpful references,
53+
most of which are available offline (if opened with `rustup doc`). Many of these
54+
resources take the form of "books"; we collectively call these "The Rust
55+
Bookshelf." Some are large, some are small.
3256

33-
Many of these resources take the form of "books"; we collectively call these
34-
"The Rust Bookshelf." Some are large, some are small.
57+
All of these books are managed by the Rust Organization, but other unofficial
58+
documentation resources are included here as well!
3559

36-
# Learn Rust
60+
If you're just looking for the standard library reference, here it is:
61+
[Rust API documentation](std/index.html)
3762

38-
If you'd like to learn Rust, this is the spot for you! All of these resources
63+
64+
## Learning Rust
65+
66+
If you'd like to learn Rust, this is the section for you! All of these resources
3967
assume that you have programmed before, but not in any specific language:
4068

41-
## The Rust Programming Language
69+
### The Rust Programming Language
4270

43-
Affectionately nicknamed "the book," [The Rust Programming
44-
Language](book/index.html) will give you an overview of the language from
45-
first principles. You'll build a few projects along the way, and by the end,
46-
you'll have a solid grasp of the language.
71+
Affectionately nicknamed "the book," [The Rust Programming Language](book/index.html)
72+
will give you an overview of the language from first principles. You'll build a
73+
few projects along the way, and by the end, you'll have a solid grasp of how to
74+
use the language.
4775

48-
## Rust By Example
76+
### Rust By Example
4977

5078
If reading multiple hundreds of pages about a language isn't your style, then
51-
[Rust By Example](rust-by-example/index.html) has you covered. While the book talks about code with
52-
a lot of words, RBE shows off a bunch of code, and keeps the talking to a
53-
minimum. It also includes exercises!
79+
[Rust By Example](rust-by-example/index.html) has you covered. RBE shows off a
80+
bunch of code without using a lot of words. It also includes exercises!
81+
82+
### Rustlings
83+
84+
[Rustlings](https://github.com/rust-lang/rustlings) guides you
85+
through downloading and setting up the Rust toolchain, then provides an
86+
interactive tool that teaches you how to solve coding challenges in Rust.
87+
88+
### Rust Playground
5489

55-
## Rustlings
90+
The [Rust Playground](https://play.rust-lang.org) is a great place
91+
to try out and share small bits of code, or experiment with some of the most
92+
popular crates.
5693

57-
[Rustlings](https://github.com/rust-lang/rustlings) guides you through downloading and setting up the Rust toolchain,
58-
and teaches you the basics of reading and writing Rust syntax. It's an
59-
alternative to Rust by Example that works with your own environment.
6094

61-
# Use Rust
95+
## Using Rust
6296

63-
Once you've gotten familiar with the language, these resources can help you
64-
when you're actually using it day-to-day.
97+
Once you've gotten familiar with the language, these resources can help you put
98+
it to work.
6599

66-
## The Standard Library
100+
### The Standard Library
67101

68-
Rust's standard library has [extensive API documentation](std/index.html),
69-
with explanations of how to use various things, as well as example code for
70-
accomplishing various tasks.
102+
Rust's standard library has [extensive API documentation](std/index.html), with
103+
explanations of how to use various things, as well as example code for
104+
accomplishing various tasks. Code examples have a "Run" button on hover that
105+
opens the sample in the playground.
71106

72107
<div>
73108
<form action="std/index.html" method="get">
@@ -77,76 +112,143 @@ accomplishing various tasks.
77112
</form>
78113
</div>
79114

80-
## The Edition Guide
115+
### Your Personal Documentation
81116

82-
[The Edition Guide](edition-guide/index.html) describes the Rust editions.
117+
Whenever you are working in a crate, `cargo doc --open` will generate
118+
documentation for your project _and_ all its dependencies in their correct
119+
version, and open it in your browser. Add the flag `--document-private-items` to
120+
also show items not marked `pub`.
83121

84-
## The Rustc Book
122+
### The Edition Guide
85123

86-
[The Rustc Book](rustc/index.html) describes the Rust compiler, `rustc`.
124+
[The Edition Guide](edition-guide/index.html) describes the Rust editions and
125+
their differences.
87126

88-
## The Cargo Book
127+
### The `rustc` Book
89128

90-
[The Cargo Book](cargo/index.html) is a guide to Cargo, Rust's build tool and dependency manager.
129+
[The `rustc` Book](rustc/index.html) describes the Rust compiler, `rustc`.
91130

92-
## The Rustdoc Book
131+
### The Cargo Book
132+
133+
[The Cargo Book](cargo/index.html) is a guide to Cargo, Rust's build tool and
134+
dependency manager.
135+
136+
### The Rustdoc Book
93137

94138
[The Rustdoc Book](rustdoc/index.html) describes our documentation tool, `rustdoc`.
95139

96-
## The Clippy Book
140+
### The Clippy Book
97141

98142
[The Clippy Book](clippy/index.html) describes our static analyzer, Clippy.
99143

100-
## Extended Error Listing
144+
### Extended Error Listing
101145

102146
Many of Rust's errors come with error codes, and you can request extended
103-
diagnostics from the compiler on those errors. You can also [read them
104-
here](error_codes/index.html), if you prefer to read them that way.
147+
diagnostics from the compiler on those errors (with `rustc --explain`). You can
148+
also read them here if you prefer: [rustc error codes](error_codes/index.html)
149+
105150

106-
# Master Rust
151+
## Mastering Rust
107152

108153
Once you're quite familiar with the language, you may find these advanced
109154
resources useful.
110155

111-
## The Reference
156+
### The Reference
112157

113-
[The Reference](reference/index.html) is not a formal spec, but is more detailed and
114-
comprehensive than the book.
158+
[The Reference](reference/index.html) is not a formal spec, but is more detailed
159+
and comprehensive than the book.
115160

116-
## The Style Guide
161+
### The Style Guide
117162

118-
[The Rust Style Guide](style-guide/index.html) describes the standard formatting of Rust
119-
code. Most developers use rustfmt to format their code, and rustfmt's default
120-
formatting matches this style guide.
163+
[The Rust Style Guide](style-guide/index.html) describes the standard formatting
164+
of Rust code. Most developers use `cargo fmt` to invoke `rustfmt` and format the
165+
code automatically (the result matches this style guide).
121166

122-
## The Rustonomicon
167+
### The Rustonomicon
123168

124-
[The Rustonomicon](nomicon/index.html) is your guidebook to the dark arts of unsafe
125-
Rust. It's also sometimes called "the 'nomicon."
169+
[The Rustonomicon](nomicon/index.html) is your guidebook to the dark arts of
170+
unsafe Rust. It's also sometimes called "the 'nomicon."
126171

127-
## The Unstable Book
172+
### The Unstable Book
128173

129-
[The Unstable Book](unstable-book/index.html) has documentation for unstable features.
174+
[The Unstable Book](unstable-book/index.html) has documentation for unstable
175+
features.
130176

131-
## The `rustc` Contribution Guide
177+
### The `rustc` Contribution Guide
132178

133-
[The `rustc` Guide](https://rustc-dev-guide.rust-lang.org/) documents how
134-
the compiler works and how to contribute to it. This is useful if you want to build
135-
or modify the Rust compiler from source (e.g. to target something non-standard).
179+
[The `rustc` Guide](https://rustc-dev-guide.rust-lang.org/)
180+
documents how the compiler works and how to contribute to it. This is useful if
181+
you want to build or modify the Rust compiler from source (e.g. to target
182+
something non-standard).
136183

137-
# Specialize Rust
138184

139-
When using Rust in specific domain areas, consider using the following resources tailored to each domain.
185+
## Specialized Rust
140186

141-
## Embedded Systems
187+
When using Rust in specific domains, consider using the following resources
188+
tailored to each area.
142189

143-
When developing for Bare Metal or Embedded Linux systems, you may find these resources maintained by the [Embedded Working Group] useful.
190+
### Embedded Systems
191+
192+
When developing for Bare Metal or Embedded Linux systems, you may find these
193+
resources maintained by the [Embedded Working Group] useful.
144194

145195
[Embedded Working Group]: https://github.com/rust-embedded
146196

147-
### The Embedded Rust Book
197+
#### The Embedded Rust Book
148198

149-
[The Embedded Rust Book] is targeted at developers familiar with embedded development and familiar with Rust, but have not used Rust for embedded development.
199+
[The Embedded Rust Book] is targeted at developers familiar with embedded
200+
development and familiar with Rust, but have not used Rust for embedded
201+
development.
150202

151203
[The Embedded Rust Book]: embedded-book/index.html
152204
[Rust project]: https://www.rust-lang.org
205+
206+
<script>
207+
// check if a given link is external
208+
function isExternalLink(url) {
209+
const tmp = document.createElement('a');
210+
tmp.href = url;
211+
return tmp.host !== window.location.host;
212+
}
213+
214+
// Add the `external` class to all <a> tags with external links and append the external link SVG
215+
function updateExternalAnchors() {
216+
/*
217+
External link SVG from Font-Awesome
218+
CC BY-SA 3.0 https://creativecommons.org/licenses/by-sa/3.0
219+
via Wikimedia Commons
220+
*/
221+
const svgText = `<svg
222+
class='external-link'
223+
xmlns='http://www.w3.org/2000/svg'
224+
viewBox='0 -256 1850 1850'
225+
width='100%'
226+
height='100%'>
227+
<g transform='matrix(1,0,0,-1,30,1427)'>
228+
<path d='M 1408,608 V 288 Q 1408,169 1323.5,84.5 1239,0 1120,
229+
0 H 288 Q 169,0 84.5,84.5 0,169 0,288 v 832 Q 0,1239 84.5,1323.5 169,
230+
1408 288,1408 h 704 q 14,0 23,-9 9,-9 9,-23 v -64 q 0,-14 -9,-23 -9,
231+
-9 -23,-9 H 288 q -66,0 -113,-47 -47,-47 -47,-113 V 288 q 0,-66 47,
232+
-113 47,-47 113,-47 h 832 q 66,0 113,47 47,47 47,113 v 320 q 0,14 9,
233+
23 9,9 23,9 h 64 q 14,0 23,-9 9,-9 9,-23 z m 384,864 V 960 q 0,
234+
-26 -19,-45 -19,-19 -45,-19 -26,0 -45,19 L 1507,1091 855,439 q -10,
235+
-10 -23,-10 -13,0 -23,10 L 695,553 q -10,10 -10,23 0,13 10,23 l 652,
236+
652 -176,176 q -19,19 -19,45 0,26 19,45 19,19 45,19 h 512 q 26,0 45,
237+
-19 19,-19 19,-45 z' style='fill:currentColor' />
238+
</g>
239+
</svg>`;
240+
let allAnchors = document.getElementsByTagName("a");
241+
242+
for (var i = 0; i < allAnchors.length; ++i) {
243+
let anchor = allAnchors[i];
244+
if (isExternalLink(anchor.href)) {
245+
anchor.classList.add("external");
246+
anchor.innerHTML += svgText;
247+
}
248+
}
249+
}
250+
251+
// on page load, update external anchors
252+
document.addEventListener("DOMContentLoaded", updateExternalAnchors);
253+
254+
</script>

0 commit comments

Comments
 (0)