Skip to content

Commit e286b72

Browse files
Merge branch 'mr/365-use_code_block_font_size_for_rust_essentials' into 'master'
Resolve "Convert latex_environment font size to code block font size" See merge request feng/training/material!607
2 parents 71df364 + ddd83f8 commit e286b72

10 files changed

Lines changed: 186 additions & 201 deletions

File tree

courses/rust_essentials/070_structs_and_enums/02_structs.rst

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,25 @@ Struct Update Operator
144144

145145
.. container:: latex_environment footnotesize
146146

147-
.. code:: rust
148-
149-
struct Settings {
150-
font_size: u8,
151-
active: bool,
152-
}
153-
let default_set = Settings {
154-
font_size: 14,
155-
active: false,
156-
};
157-
// Only change 'active' to true in 'set_1'
158-
let set_1 = Settings {
159-
active: true, // Overridden field
160-
..default_set // Copy all other fields ('font_size')
161-
};
162-
let set_2 = Settings {
163-
..default_set // Copy all fields
164-
};
147+
.. code:: rust
148+
:font-size: footnotesize
149+
150+
struct Settings {
151+
font_size: u8,
152+
active: bool,
153+
}
154+
let default_set = Settings {
155+
font_size: 14,
156+
active: false,
157+
};
158+
// Only change 'active' to true in 'set_1'
159+
let set_1 = Settings {
160+
active: true, // Overridden field
161+
..default_set // Copy all other fields ('font_size')
162+
};
163+
let set_2 = Settings {
164+
..default_set // Copy all fields
165+
};
165166
166167
.. warning:: Fields are *moved* if their type doesn't implement the :rust:`Copy` trait
167168

courses/rust_essentials/080_pattern_matching/03_destructuring_structs.rst

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,26 @@ Ignoring Fields
113113

114114
- Useful when only part of a struct matters
115115

116-
.. container:: latex_environment scriptsize
117-
118-
.. code:: rust
116+
.. code:: rust
117+
:font-size: scriptsize
119118
120-
struct PhysicsObject {
121-
id: u32,
122-
x: i32,
123-
y: i32,
124-
velocity: f64,
125-
}
119+
struct PhysicsObject {
120+
id: u32,
121+
x: i32,
122+
y: i32,
123+
velocity: f64,
124+
}
126125
127-
let obj = PhysicsObject { id: 1, x: 10, y: 20, velocity: 5.5 };
126+
let obj = PhysicsObject { id: 1, x: 10, y: 20, velocity: 5.5 };
128127
129-
// Capture 'x' and ignore all other fields
130-
let PhysicsObject { x, .. } = obj;
128+
// Capture 'x' and ignore all other fields
129+
let PhysicsObject { x, .. } = obj;
131130
132-
// Ignore a specific field by name using '_'
133-
let PhysicsObject { id, velocity: _, .. } = obj;
131+
// Ignore a specific field by name using '_'
132+
let PhysicsObject { id, velocity: _, .. } = obj;
134133
135-
// Capturing multiple specific fields
136-
let PhysicsObject { id, velocity, .. } = obj;
134+
// Capturing multiple specific fields
135+
let PhysicsObject { id, velocity, .. } = obj;
137136
138137
.. note::
139138

courses/rust_essentials/080_pattern_matching/04_destructuring_enums.rst

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,20 @@ Tuple Variants
9494

9595
- Patterns mirror the variant structure
9696

97-
.. container:: latex_environment scriptsize
98-
99-
.. code:: rust
97+
.. code:: rust
98+
:font-size: scriptsize
10099
101-
enum Event {
102-
KeyPress(char),
103-
MouseClick(i32, i32),
104-
}
100+
enum Event {
101+
KeyPress(char),
102+
MouseClick(i32, i32),
103+
}
105104
106-
let touch = Event::MouseClick(10, 20);
105+
let touch = Event::MouseClick(10, 20);
107106
108-
match touch {
109-
Event::KeyPress(tap) => println!("key: {}", tap),
110-
Event::MouseClick(x, y) => println!("click at {}, {}", x, y),
111-
}
107+
match touch {
108+
Event::KeyPress(tap) => println!("key: {}", tap),
109+
Event::MouseClick(x, y) => println!("click at {}, {}", x, y),
110+
}
112111
113112
:command:`click at 10, 20`
114113

@@ -122,28 +121,27 @@ Struct Variants
122121

123122
- Partial matching is supported
124123

125-
.. container:: latex_environment tiny
126-
127-
.. code:: rust
128-
129-
enum Shape {
130-
Circle { radius: f64 },
131-
Rectangle { width: f64, height: f64 },
132-
}
124+
.. code:: rust
125+
:font-size: tiny
133126
134-
let profile = Shape::Rectangle { width: 3.0, height: 4.0 };
127+
enum Shape {
128+
Circle { radius: f64 },
129+
Rectangle { width: f64, height: f64 },
130+
}
135131
136-
match profile {
137-
Shape::Circle { radius } => {
138-
println!("circle r={}", radius)
139-
}
140-
Shape::Rectangle {
141-
width,
142-
height,
143-
} => {
144-
println!("rect {} x {}", width, height);
145-
}
146-
}
132+
let profile = Shape::Rectangle { width: 3.0, height: 4.0 };
133+
134+
match profile {
135+
Shape::Circle { radius } => {
136+
println!("circle r={}", radius)
137+
}
138+
Shape::Rectangle {
139+
width,
140+
height,
141+
} => {
142+
println!("rect {} x {}", width, height);
143+
}
144+
}
147145
148146
:command:`rect 3 x 4`
149147

courses/rust_essentials/090_methods_and_traits/02-methods.rst

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,22 @@ Methods in Rust
1414

1515
* Organize behavior with the data it operates on
1616

17+
.. code:: rust
18+
:font-size: tiny
1719
18-
.. container:: latex_environment tiny
19-
20-
.. code:: rust
20+
struct CarRace {
21+
laps: Vec<i32>,
22+
}
2123
22-
struct CarRace {
23-
laps: Vec<i32>,
24-
}
25-
26-
impl CarRace {
27-
// Method: Modify data
28-
fn record_lap(&mut self, time: i32) {
29-
self.laps.push(time);
30-
}
31-
}
24+
impl CarRace {
25+
// Method: Modify data
26+
fn record_lap(&mut self, time: i32) {
27+
self.laps.push(time);
28+
}
29+
}
3230
33-
let mut race = CarRace::new();
34-
race.record_lap(114); // Data and logic live together
31+
let mut race = CarRace::new();
32+
race.record_lap(114); // Data and logic live together
3533
3634
----------------------------
3735
What Is a Method Receiver?

courses/rust_essentials/130_memory_management/03_ownership.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ Ownership Principles
3737
{
3838
let poodle = String::from("ball"); // 'poodle' owns the ball
3939
let yorkie = poodle; // 'poodle' lets go, 'yorkie' picked it up
40-
40+
4141
// println!("{}", poodle); // Error
4242
println!("{}", yorkie);
4343
} // 'yorkie' drops the ball, and leaves
44-
// 'poodle' leaves quietly
45-
46-
:command:`ball`
44+
// 'poodle' leaves quietly

courses/rust_essentials/180_modules/04-encapsulation.rst

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,21 @@ Encapsulation in Structs
3232

3333
* Control how data is read or modified
3434

35-
.. container:: latex_environment scriptsize
36-
37-
.. code:: rust
38-
39-
pub struct Students {
40-
names: Vec<String>, // Private!
41-
}
42-
43-
impl Students {
44-
pub fn new() -> Self {
45-
Self { names: Vec::new() }
46-
}
47-
pub fn add(&mut self, name: String) {
48-
if !name.is_empty() { self.names.push(name); }
49-
}
50-
}
35+
.. code:: rust
36+
:font-size: scriptsize
37+
38+
pub struct Students {
39+
names: Vec<String>, // Private!
40+
}
41+
42+
impl Students {
43+
pub fn new() -> Self {
44+
Self { names: Vec::new() }
45+
}
46+
pub fn add(&mut self, name: String) {
47+
if !name.is_empty() { self.names.push(name); }
48+
}
49+
}
5150
5251
--------------------------------------------
5352
Breaking Encapsulation - Or, When to "pub"

courses/rust_essentials/200_error_handling/03-result.rst

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ Recoverable Error
1313

1414
* :rust:`Result` allows safe handling of any outcome
1515

16-
.. container:: latex_environment footnotesize
17-
18-
.. code:: rust
16+
.. code:: rust
17+
:font-size: footnotesize
1918
20-
enum Result<T, E> {
21-
Ok(T), // Success - contains value of type 'T'
22-
Err(E), // Failure - contains error of type 'E'
23-
}
19+
enum Result<T, E> {
20+
Ok(T), // Success - contains value of type 'T'
21+
Err(E), // Failure - contains error of type 'E'
22+
}
2423
2524
.. note::
2625

@@ -89,16 +88,15 @@ Propagating Errors
8988

9089
* Called the :dfn:`Try Operator`
9190

92-
.. container:: latex_environment footnotesize
91+
.. code:: rust
92+
:font-size: footnotesize
9393
94-
.. code:: rust
95-
96-
fn open_file(filename: &str) -> Result<File, io::Error> {
97-
// 'open' returns 'Result'
98-
// '?' returns to caller if 'Result' is 'Err'
99-
let mut file = File::open("user.txt")?;
100-
Ok(file)
101-
}
94+
fn open_file(filename: &str) -> Result<File, io::Error> {
95+
// 'open' returns 'Result'
96+
// '?' returns to caller if 'Result' is 'Err'
97+
let mut file = File::open("user.txt")?;
98+
Ok(file)
99+
}
102100
103101
.. note::
104102

0 commit comments

Comments
 (0)