Skip to content

Commit c655ede

Browse files
Use rust role for syntax highlighting
1 parent 71c6490 commit c655ede

File tree

119 files changed

+1303
-1659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1303
-1659
lines changed

courses/comprehensive_rust_training/020_hello_world/01_what_is_rust.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Rust is a new programming language which had its `1.0 release in
1111

1212
- Rust is a statically compiled language in a similar role as C++
1313

14-
- ``rustc`` uses LLVM as its backend.
14+
- :rust:`rustc` uses LLVM as its backend.
1515

1616
- Rust supports many `platforms and
1717
architectures <https://doc.rust-lang.org/nightly/rustc/platform-support.html>`__:
@@ -27,8 +27,6 @@ Rust is a new programming language which had its `1.0 release in
2727
- desktops,
2828
- servers.
2929

30-
.. raw:: html
31-
3230
---------
3331
Details
3432
---------
@@ -41,6 +39,3 @@ Rust fits in the same area as C++:
4139
microcontrollers.
4240
- Has no runtime or garbage collection.
4341
- Focuses on reliability and safety without sacrificing performance.
44-
45-
.. raw:: html
46-

courses/comprehensive_rust_training/020_hello_world/02_benefits.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Some unique selling points of Rust:
1414
- No uninitialized variables.
1515
- No double-frees.
1616
- No use-after-free.
17-
- No ``NULL`` pointers.
17+
- No :rust:`NULL` pointers.
1818
- No forgotten locked mutexes.
1919
- No data races between threads.
2020
- No iterator invalidation.
@@ -37,8 +37,6 @@ Some unique selling points of Rust:
3737
- Built-in support for testing.
3838
- Excellent Language Server Protocol support.
3939

40-
.. raw:: html
41-
4240
---------
4341
Details
4442
---------
@@ -60,6 +58,3 @@ Depending on the answer you can highlight different features of Rust:
6058
language feeling. In addition you get fast and predictable
6159
performance like C and C++ (no garbage collector) as well as access
6260
to low-level hardware (should you need it).
63-
64-
.. raw:: html
65-

courses/comprehensive_rust_training/020_hello_world/03_playground.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ way to run short Rust programs, and is the basis for the examples and
1111
exercises in this course. Try running the "hello-world" program it
1212
starts with. It comes with a few handy features:
1313

14-
- Under "Tools", use the ``rustfmt`` option to format your code in the
14+
- Under "Tools", use the :rust:`rustfmt` option to format your code in the
1515
"standard" way.
1616

1717
- Rust has two main "profiles" for generating code: Debug (extra
@@ -21,8 +21,6 @@ starts with. It comes with a few handy features:
2121
- If you're interested, use "ASM" under "..." to see the generated
2222
assembly code.
2323

24-
.. raw:: html
25-
2624
---------
2725
Details
2826
---------
@@ -32,6 +30,3 @@ playground and experiment a little. Encourage them to keep the tab open
3230
and try things out during the rest of the course. This is particularly
3331
helpful for advanced students who want to know more about Rust's
3432
optimizations or generated assembly.
35-
36-
.. raw:: html
37-

courses/comprehensive_rust_training/030_types_and_values/01_hello_world.rst

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@ Hello, World
99
Let us jump into the simplest possible Rust program, a classic Hello
1010
World program:
1111

12-
.. code:: rust,editable
12+
.. code:: rust
1313
1414
fn main() {
1515
println!("Hello World!");
1616
}
1717
1818
What you see:
1919

20-
- Functions are introduced with ``fn``.
20+
- Functions are introduced with :rust:`fn`.
2121
- Blocks are delimited by curly braces like in C and C++.
22-
- The ``main`` function is the entry point of the program.
23-
- Rust has hygienic macros, ``println!`` is an example of this.
22+
- The :rust:`main` function is the entry point of the program.
23+
- Rust has hygienic macros, :rust:`println!` is an example of this.
2424
- Rust strings are UTF-8 encoded and can contain any Unicode character.
2525

26-
.. raw:: html
27-
2826
---------
2927
Details
3028
---------
@@ -56,6 +54,3 @@ Key points:
5654
while it is not a functional language, it includes a range of
5755
`functional
5856
concepts <https://doc.rust-lang.org/book/ch13-00-functional-features.html>`__.
59-
60-
.. raw:: html
61-

courses/comprehensive_rust_training/030_types_and_values/02_variables.rst

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ Variables
77
-----------
88

99
Rust provides type safety via static typing. Variable bindings are made
10-
with ``let``:
10+
with :rust:`let`:
1111

12-
.. code:: rust,editable,warnunused
12+
.. code:: rust
1313
1414
fn main() {
1515
let x: i32 = 10;
@@ -18,23 +18,18 @@ with ``let``:
1818
// println!("x: {x}");
1919
}
2020
21-
.. raw:: html
22-
2321
---------
2422
Details
2523
---------
2624

27-
- Uncomment the ``x = 20`` to demonstrate that variables are immutable
28-
by default. Add the ``mut`` keyword to allow changes.
25+
- Uncomment the :rust:`x = 20` to demonstrate that variables are immutable
26+
by default. Add the :rust:`mut` keyword to allow changes.
2927

3028
- Warnings are enabled for this slide, such as for unused variables or
31-
unnecessary ``mut``. These are omitted in most slides to avoid
29+
unnecessary :rust:`mut`. These are omitted in most slides to avoid
3230
distracting warnings. Try removing the mutation but leaving the
33-
``mut`` keyword in place.
31+
:rust:`mut` keyword in place.
3432

35-
- The ``i32`` here is the type of the variable. This must be known at
33+
- The :rust:`i32` here is the type of the variable. This must be known at
3634
compile time, but type inference (covered later) allows the
3735
programmer to omit it in many cases.
38-
39-
.. raw:: html
40-

courses/comprehensive_rust_training/030_types_and_values/03_values.rst

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,10 @@ each type.
3838

3939
The types have widths as follows:
4040

41-
- ``iN``, ``uN``, and ``fN`` are *N* bits wide,
42-
- ``isize`` and ``usize`` are the width of a pointer,
43-
- ``char`` is 32 bits wide,
44-
- ``bool`` is 8 bits wide.
45-
46-
.. raw:: html
41+
- :rust:`iN`, :rust:`uN`, and :rust:`fN` are *N* bits wide,
42+
- :rust:`isize` and :rust:`usize` are the width of a pointer,
43+
- :rust:`char` is 32 bits wide,
44+
- :rust:`bool` is 8 bits wide.
4745

4846
---------
4947
Details
@@ -52,8 +50,5 @@ Details
5250
There are a few syntaxes which are not shown above:
5351

5452
- All underscores in numbers can be left out, they are for legibility
55-
only. So ``1_000`` can be written as ``1000`` (or ``10_00``), and
56-
``123_i64`` can be written as ``123i64``.
57-
58-
.. raw:: html
59-
53+
only. So :rust:`1_000` can be written as :rust:`1000` (or :rust:`10_00`), and
54+
:rust:`123_i64` can be written as :rust:`123i64`.

courses/comprehensive_rust_training/030_types_and_values/04_arithmetic.rst

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Arithmetic
66
Arithmetic
77
------------
88

9-
.. code:: rust,editable
9+
.. code:: rust
1010
1111
fn interproduct(a: i32, b: i32, c: i32) -> i32 {
1212
return a * b + b * c + c * a;
@@ -16,13 +16,11 @@ Arithmetic
1616
println!("result: {}", interproduct(120, 100, 248));
1717
}
1818
19-
.. raw:: html
20-
2119
---------
2220
Details
2321
---------
2422

25-
This is the first time we've seen a function other than ``main``, but
23+
This is the first time we've seen a function other than :rust:`main`, but
2624
the meaning should be clear: it takes three integers, and returns an
2725
integer. Functions will be covered in more detail later.
2826

@@ -32,14 +30,11 @@ What about integer overflow? In C and C++ overflow of *signed* integers
3230
is actually undefined, and might do unknown things at runtime. In Rust,
3331
it's defined.
3432

35-
Change the ``i32``\ 's to ``i16`` to see an integer overflow, which
33+
Change the :rust:`i32` to :rust:`i16` to see an integer overflow, which
3634
panics (checked) in a debug build and wraps in a release build. There
3735
are other options, such as overflowing, saturating, and carrying. These
3836
are accessed with method syntax, e.g.,
39-
``(a * b).saturating_add(b * c).saturating_add(c * a)``.
37+
:rust:`(a * b).saturating_add(b * c).saturating_add(c * a)`.
4038

4139
In fact, the compiler will detect overflow of constant expressions,
4240
which is why the example requires a separate function.
43-
44-
.. raw:: html
45-

courses/comprehensive_rust_training/030_types_and_values/05_inference.rst

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ Type Inference
88

99
Rust will look at how the variable is *used* to determine the type:
1010

11-
.. raw:: html
12-
13-
<!-- mdbook-xgettext: skip -->
14-
15-
.. code:: rust,editable
11+
.. code:: rust
1612
1713
fn takes_u32(x: u32) {
1814
println!("u32: {x}");
@@ -31,8 +27,6 @@ Rust will look at how the variable is *used* to determine the type:
3127
// takes_u32(y);
3228
}
3329
34-
.. raw:: html
35-
3630
---------
3731
Details
3832
---------
@@ -47,17 +41,14 @@ declaration of a type. The compiler does the job for us and helps us
4741
write more concise code.
4842

4943
When nothing constrains the type of an integer literal, Rust defaults to
50-
``i32``. This sometimes appears as ``{integer}`` in error messages.
51-
Similarly, floating-point literals default to ``f64``.
44+
:rust:`i32`. This sometimes appears as :rust:`{integer}` in error messages.
45+
Similarly, floating-point literals default to :rust:`f64`.
5246

53-
.. code:: rust,compile_fail
47+
.. code:: rust
5448
5549
fn main() {
5650
let x = 3.14;
5751
let y = 20;
5852
assert_eq!(x, y);
5953
// ERROR: no implementation for `{float} == {integer}`
6054
}
61-
62-
.. raw:: html
63-

courses/comprehensive_rust_training/030_types_and_values/06_exercise.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ Exercise: Fibonacci
66
Exercise: Fibonacci
77
---------------------
88

9-
The Fibonacci sequence begins with ``[0,1]``. For n>1, the n'th
9+
The Fibonacci sequence begins with :rust:`[0,1]`. For n>1, the n'th
1010
Fibonacci number is calculated recursively as the sum of the n-1'th and
1111
n-2'th Fibonacci numbers.
1212

13-
Write a function ``fib(n)`` that calculates the n'th Fibonacci number.
13+
Write a function :rust:`fib(n)` that calculates the n'th Fibonacci number.
1414
When will this function panic?
1515

16-
.. code:: rust,editable,should_panic
16+
::
1717

1818
{{#include exercise.rs:fib}}
1919
if n < 2 {
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
====================
2-
``if`` expressions
2+
"if" expressions
33
====================
44

55
--------------------
6-
``if`` expressions
6+
"if" expressions
77
--------------------
88

99
You use
1010
:url:`if expressions <https://doc.rust-lang.org/reference/expressions/if-expr.html#if-expressions>`
11-
exactly like ``if`` statements in other languages:
11+
exactly like :rust:`if` statements in other languages:
1212

13-
.. code:: rust,editable
13+
.. code:: rust
1414
1515
fn main() {
1616
let x = 10;
@@ -23,31 +23,26 @@ exactly like ``if`` statements in other languages:
2323
}
2424
}
2525
26-
In addition, you can use ``if`` as an expression. The last expression of
27-
each block becomes the value of the ``if`` expression:
26+
In addition, you can use :rust:`if` as an expression. The last expression of
27+
each block becomes the value of the :rust:`if` expression:
2828

29-
.. code:: rust,editable
29+
.. code:: rust
3030
3131
fn main() {
3232
let x = 10;
3333
let size = if x < 20 { "small" } else { "large" };
3434
println!("number size: {}", size);
3535
}
3636
37-
.. raw:: html
38-
3937
---------
4038
Details
4139
---------
4240

43-
Because ``if`` is an expression and must have a particular type, both of
41+
Because :rust:`if` is an expression and must have a particular type, both of
4442
its branch blocks must have the same type. Show what happens if you add
45-
``;`` after ``"small"`` in the second example.
46-
47-
An ``if`` expression should be used in the same way as the other
48-
expressions. For example, when it is used in a ``let`` statement, the
49-
statement must be terminated with a ``;`` as well. Remove the ``;``
50-
before ``println!`` to see the compiler error.
51-
52-
.. raw:: html
43+
:rust:`;` after :rust:`"small"` in the second example.
5344

45+
An :rust:`if` expression should be used in the same way as the other
46+
expressions. For example, when it is used in a :rust:`let` statement, the
47+
statement must be terminated with a :rust:`;` as well. Remove the :rust:`;`
48+
before :rust:`println!` to see the compiler error.

0 commit comments

Comments
 (0)