Skip to content

Commit 6f69cd6

Browse files
committed
TRPL: Add rust Marker to Some Code Block
This adds strictly more information to the source files and reduces the need for customized tooling to render the book. (While this should not change the output of _rustbook_, it is very useful when rendering the sources with external tools like Pandoc.)
1 parent 2dd5ad0 commit 6f69cd6

21 files changed

+72
-71
lines changed

src/doc/trpl/borrow-and-asref.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ kind of borrowed value. Slices are an area where this is especially true: you
5151
can have both an `&[T]` or a `&mut [T]`. If we wanted to accept both of these
5252
types, `Borrow` is up for it:
5353

54-
```
54+
```rust
5555
use std::borrow::Borrow;
5656
use std::fmt::Display;
5757

src/doc/trpl/box-syntax-and-patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Also it is not possible in stable Rust to destructure a `Box` in a match
55
pattern. The unstable `box` keyword can be used to both create and destructure
66
a `Box`. An example usage would be:
77

8-
```
8+
```rust
99
#![feature(box_syntax, box_patterns)]
1010

1111
fn main() {

src/doc/trpl/concurrency.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ place!
5959
Rust's standard library provides a library for threads, which allow you to
6060
run Rust code in parallel. Here's a basic example of using `std::thread`:
6161

62-
```
62+
```rust
6363
use std::thread;
6464

6565
fn main() {
@@ -73,7 +73,7 @@ The `thread::spawn()` method accepts a closure, which is executed in a
7373
new thread. It returns a handle to the thread, that can be used to
7474
wait for the child thread to finish and extract its result:
7575

76-
```
76+
```rust
7777
use std::thread;
7878

7979
fn main() {
@@ -189,7 +189,7 @@ guard across thread boundaries, which gives us our error.
189189

190190
We can use `Arc<T>` to fix this. Here's the working version:
191191

192-
```
192+
```rust
193193
use std::sync::{Arc, Mutex};
194194
use std::thread;
195195

@@ -248,7 +248,7 @@ threads with each other. Let's talk about one of them: channels.
248248
Here's a version of our code that uses channels for synchronization, rather
249249
than waiting for a specific time:
250250

251-
```
251+
```rust
252252
use std::sync::{Arc, Mutex};
253253
use std::thread;
254254
use std::sync::mpsc;
@@ -281,7 +281,7 @@ a simple `()` down the channel, and then wait for ten of them to come back.
281281
While this channel is just sending a generic signal, we can send any data that
282282
is `Send` over the channel!
283283

284-
```
284+
```rust
285285
use std::thread;
286286
use std::sync::mpsc;
287287

@@ -311,7 +311,7 @@ the answer, and then it `send()`s us the answer over the channel.
311311
A `panic!` will crash the currently executing thread. You can use Rust's
312312
threads as a simple isolation mechanism:
313313

314-
```
314+
```rust
315315
use std::thread;
316316

317317
let result = thread::spawn(move || {

src/doc/trpl/crates-and-modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ above.
7575
To define each of our modules, we use the `mod` keyword. Let’s make our
7676
`src/lib.rs` look like this:
7777

78-
```
78+
```rust
7979
mod english {
8080
mod greetings {
8181
}

src/doc/trpl/documentation.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Documentation comments are written in Markdown.
4242
Rust keeps track of these comments, and uses them when generating
4343
documentation. This is important when documenting things like enums:
4444

45-
```
45+
```rust
4646
/// The `Option` type. See [the module level documentation](../) for more.
4747
enum Option<T> {
4848
/// No value
@@ -80,15 +80,15 @@ thing after that last comment.
8080

8181
Anyway, let's cover each part of this comment in detail:
8282

83-
```
83+
```rust
8484
/// Constructs a new `Rc<T>`.
8585
# fn foo() {}
8686
```
8787

8888
The first line of a documentation comment should be a short summary of its
8989
functionality. One sentence. Just the basics. High level.
9090

91-
```
91+
```rust
9292
///
9393
/// Other details about constructing `Rc<T>`s, maybe describing complicated
9494
/// semantics, maybe additional options, all kinds of stuff.
@@ -101,7 +101,7 @@ we could have added more explanation in a new paragraph.
101101

102102
#### Special sections
103103

104-
```
104+
```rust
105105
/// # Examples
106106
# fn foo() {}
107107
```
@@ -110,7 +110,7 @@ Next, are special sections. These are indicated with a header, `#`. There
110110
are three kinds of headers that are commonly used. They aren't special syntax,
111111
just convention, for now.
112112

113-
```
113+
```rust
114114
/// # Panics
115115
# fn foo() {}
116116
```
@@ -120,7 +120,7 @@ usually indicated by panics, which kill the whole current thread at the very
120120
least. If your function has a non-trivial contract like this, that is
121121
detected/enforced by panics, documenting it is very important.
122122

123-
```
123+
```rust
124124
/// # Failures
125125
# fn foo() {}
126126
```
@@ -130,15 +130,15 @@ conditions under which it returns `Err(E)` is a nice thing to do. This is
130130
slightly less important than `Panics`, because failure is encoded into the type
131131
system, but it's still a good thing to do.
132132

133-
```
133+
```rust
134134
/// # Safety
135135
# fn foo() {}
136136
```
137137

138138
If your function is `unsafe`, you should explain which invariants the caller is
139139
responsible for upholding.
140140

141-
```
141+
```rust
142142
/// # Examples
143143
///
144144
/// ```
@@ -154,7 +154,7 @@ method, and your users will love you for it. These examples go inside of
154154
code block annotations, which we'll talk about in a moment, and can have
155155
more than one section:
156156

157-
```
157+
```rust
158158
/// # Examples
159159
///
160160
/// Simple `&str` patterns:
@@ -179,7 +179,7 @@ Let's discuss the details of these code blocks.
179179

180180
To write some Rust code in a comment, use the triple graves:
181181

182-
```
182+
```rust
183183
/// ```
184184
/// println!("Hello, world");
185185
/// ```
@@ -188,7 +188,7 @@ To write some Rust code in a comment, use the triple graves:
188188

189189
If you want something that's not Rust code, you can add an annotation:
190190

191-
```
191+
```rust
192192
/// ```c
193193
/// printf("Hello, world\n");
194194
/// ```
@@ -208,7 +208,7 @@ generate the documentation.
208208

209209
Let's discuss our sample example documentation:
210210

211-
```
211+
```rust
212212
/// ```
213213
/// println!("Hello, world");
214214
/// ```
@@ -219,7 +219,7 @@ You'll notice that you don't need a `fn main()` or anything here. `rustdoc` will
219219
automatically add a main() wrapper around your code, and in the right place.
220220
For example:
221221

222-
```
222+
```rust
223223
/// ```
224224
/// use std::rc::Rc;
225225
///
@@ -230,7 +230,7 @@ For example:
230230

231231
This will end up testing:
232232

233-
```
233+
```rust
234234
fn main() {
235235
use std::rc::Rc;
236236
let five = Rc::new(5);
@@ -259,7 +259,7 @@ with `///` we've been talking about? The raw text:
259259

260260
looks different than the output:
261261

262-
```
262+
```rust
263263
/// Some documentation.
264264
# fn foo() {}
265265
```
@@ -274,7 +274,7 @@ it makes the example more clear. You can use this technique to explain
274274
longer examples in detail, while still preserving the testability of your
275275
documentation. For example, this code:
276276

277-
```
277+
```rust
278278
let x = 5;
279279
let y = 6;
280280
println!("{}", x + y);
@@ -284,23 +284,23 @@ Here's an explanation, rendered:
284284

285285
First, we set `x` to five:
286286

287-
```
287+
```rust
288288
let x = 5;
289289
# let y = 6;
290290
# println!("{}", x + y);
291291
```
292292

293293
Next, we set `y` to six:
294294

295-
```
295+
```rust
296296
# let x = 5;
297297
let y = 6;
298298
# println!("{}", x + y);
299299
```
300300

301301
Finally, we print the sum of `x` and `y`:
302302

303-
```
303+
```rust
304304
# let x = 5;
305305
# let y = 6;
306306
println!("{}", x + y);
@@ -340,7 +340,7 @@ explanation.
340340
341341
Here’s an example of documenting a macro:
342342
343-
```
343+
```rust
344344
/// Panic with a given message unless an expression evaluates to true.
345345
///
346346
/// # Examples
@@ -388,7 +388,7 @@ but with a binary, there’s nothing to link to.
388388
There are a few more annotations that are useful to help `rustdoc` do the right
389389
thing when testing your code:
390390

391-
```
391+
```rust
392392
/// ```ignore
393393
/// fn foo() {
394394
/// ```
@@ -400,7 +400,7 @@ what you want, as it's the most generic. Instead, consider annotating it
400400
with `text` if it's not code, or using `#`s to get a working example that
401401
only shows the part you care about.
402402

403-
```
403+
```rust
404404
/// ```should_panic
405405
/// assert!(false);
406406
/// ```
@@ -410,7 +410,7 @@ only shows the part you care about.
410410
`should_panic` tells `rustdoc` that the code should compile correctly, but
411411
not actually pass as a test.
412412

413-
```
413+
```rust
414414
/// ```no_run
415415
/// loop {
416416
/// println!("Hello, world");
@@ -427,7 +427,7 @@ which you would want to make sure compile, but might run in an infinite loop!
427427

428428
Rust has another kind of doc comment, `//!`. This comment doesn't document the next item, but the enclosing item. In other words:
429429

430-
```
430+
```rust
431431
mod foo {
432432
//! This is documentation for the `foo` module.
433433
//!
@@ -440,7 +440,7 @@ mod foo {
440440
This is where you'll see `//!` used most often: for module documentation. If
441441
you have a module in `foo.rs`, you'll often open its code and see this:
442442

443-
```
443+
```rust
444444
//! A module for using `foo`s.
445445
//!
446446
//! The `foo` module contains a lot of useful functionality blah blah blah
@@ -461,7 +461,7 @@ are written in Markdown, they're often `.md` files.
461461
When you write documentation in Markdown files, you don't need to prefix
462462
the documentation with comments. For example:
463463

464-
```
464+
```rust
465465
/// # Examples
466466
///
467467
/// ```
@@ -499,7 +499,7 @@ This `%` line needs to be the very first line of the file.
499499

500500
At a deeper level, documentation comments are sugar for documentation attributes:
501501

502-
```
502+
```rust
503503
/// this
504504
# fn foo() {}
505505

@@ -509,7 +509,7 @@ At a deeper level, documentation comments are sugar for documentation attributes
509509

510510
are the same, as are these:
511511

512-
```
512+
```rust
513513
//! this
514514

515515
#![doc="/// this"]
@@ -546,7 +546,7 @@ pub use foo::bar;
546546
You can control a few aspects of the HTML that `rustdoc` generates through the
547547
`#![doc]` version of the attribute:
548548

549-
```
549+
```rust
550550
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
551551
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
552552
html_root_url = "http://doc.rust-lang.org/")];

src/doc/trpl/ffi.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ vectors as pointers to memory. Rust's vectors are guaranteed to be a contiguous
8181
length is number of elements currently contained, and the capacity is the total size in elements of
8282
the allocated memory. The length is less than or equal to the capacity.
8383

84-
```
84+
```rust
8585
# #![feature(libc)]
8686
# extern crate libc;
8787
# use libc::{c_int, size_t};
@@ -106,7 +106,7 @@ required capacity to hold the compressed output. The vector can then be passed t
106106
`snappy_compress` function as an output parameter. An output parameter is also passed to retrieve
107107
the true length after compression for setting the length.
108108

109-
```
109+
```rust
110110
# #![feature(libc)]
111111
# extern crate libc;
112112
# use libc::{size_t, c_int};
@@ -133,7 +133,7 @@ pub fn compress(src: &[u8]) -> Vec<u8> {
133133
Decompression is similar, because snappy stores the uncompressed size as part of the compression
134134
format and `snappy_uncompressed_length` will retrieve the exact buffer size required.
135135

136-
```
136+
```rust
137137
# #![feature(libc)]
138138
# extern crate libc;
139139
# use libc::{size_t, c_int};
@@ -375,7 +375,7 @@ the compiler that the unsafety does not leak out of the block.
375375
Unsafe functions, on the other hand, advertise it to the world. An unsafe function is written like
376376
this:
377377
378-
```
378+
```rust
379379
unsafe fn kaboom(ptr: *const i32) -> i32 { *ptr }
380380
```
381381

@@ -439,7 +439,7 @@ Most foreign code exposes a C ABI, and Rust uses the platform's C calling conven
439439
calling foreign functions. Some foreign functions, most notably the Windows API, use other calling
440440
conventions. Rust provides a way to tell the compiler which convention to use:
441441

442-
```
442+
```rust
443443
# #![feature(libc)]
444444
extern crate libc;
445445

@@ -516,7 +516,7 @@ function pointer using the C ABI.
516516
You may wish to compile Rust code in a way so that it can be called from C. This is
517517
fairly easy, but requires a few things:
518518

519-
```
519+
```rust
520520
#[no_mangle]
521521
pub extern fn hello_rust() -> *const u8 {
522522
"Hello, world!\0".as_ptr()

0 commit comments

Comments
 (0)