Skip to content

Commit 31654c7

Browse files
committed
WIP on improving slides
1 parent 7a2e366 commit 31654c7

17 files changed

+195
-159
lines changed

slides/A-foundations/basic-syntax.md

+23-12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ that variable
8484
```rust
8585
fn main() {
8686
let x: i32 = 20;
87+
// ^^^^^ Type annotation
8788
}
8889
```
8990

@@ -242,14 +243,14 @@ then the code for b is not executed
242243

243244
```rust
244245
fn main() {
245-
let c = 'z';
246+
let c: char = 'z';
246247
let z = 'ℤ';
247248
let heart_eyed_cat = '😻';
248249
}
249250
```
250251

251-
- A character is a 32-bit unicode scalar value
252-
- Very much unlike C/C++ where char is 8 bits
252+
- A `char` is a 32-bit unicode scalar value
253+
- Very much unlike C/C++ where `char is 8 bits
253254

254255
<!--
255256
- The final scalar type is the character, but it isn't often seen.
@@ -261,16 +262,22 @@ instead.
261262

262263
---
263264

264-
# Strings
265+
# `String`s
265266
```rust
266-
// Owned, heap-allocated string *slice*
267-
let s1: String = String::new("Hello, 🌍!");
267+
268+
let s1 = String::new("Hello, 🌍!");
269+
// ^^^^^^ Owned, heap-allocated string
268270
```
269271

270-
- Rust strings are UTF-8-encoded
272+
- Rust `String`s are UTF-8-encoded
271273
- Unlike C/C++: *Not null-terminated*
272274
- Cannot be indexed like C strings
275+
- `String` is heap-allocated
273276
- Actually many types of strings in Rust
277+
- `CString`
278+
- `PathBuf`
279+
- `OsString`
280+
- ...
274281

275282
<!--
276283
- Rusts strings are complicated, because all strings are complicated
@@ -294,7 +301,7 @@ fn main() {
294301
- Group multiple values into a single compound type
295302
- Fixed size
296303
- Different types per element
297-
- Create a tuple by writing a comma-separated list of values inside parentheses
304+
- Create by writing a comma-separated list of values inside parentheses
298305

299306
::right::
300307

@@ -406,9 +413,9 @@ fn also_returns_nothing() {
406413
```
407414

408415
- The function boundary must always be explicitly annotated with types
409-
- Within the function body type inference may be used
416+
- Type inference may be used in function body
410417
- A function that returns nothing has the return type *unit* (`()`)
411-
- The function body contains a series of statements optionally ending with an
418+
- Function body contains a series of statements optionally ending with an
412419
expression
413420

414421
<!--
@@ -440,6 +447,10 @@ fn my_fun() {
440447
let x = 10;
441448
```
442449

450+
```rust
451+
return 42;
452+
```
453+
443454
<v-click>
444455

445456
```rust
@@ -465,9 +476,9 @@ statements
465476

466477
- Expressions evaluate to a resulting value
467478
- Expressions make up most of the Rust code you write
468-
- Includes all control flow such as `if` and `while`
479+
- Includes all control flow such as `if` and `loop`
469480
- Includes scoping braces (`{` and `}`)
470-
- An expression can be turned into a statement by adding a semicolon (`;`)
481+
- Semicolon (`;`) turns expression into statement
471482

472483
```rust {all|2-5}
473484
fn main() {

slides/A-foundations/closures.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: default
33
---
4-
# Intermezzo: Closures
4+
# Closures
55

66
- Closures are anonymous (unnamed) functions
77
- they can capture ("close over") values in their scope
@@ -28,3 +28,8 @@ fn bar() -> i64 {
2828
let evens: Vec<_> = some_iterator.filter(|x| x % 2 == 0).collect();
2929
```
3030

31+
---
32+
33+
# To do
34+
35+
Issue: [tweedegolf/101-rs#66](https://github.com/tweedegolf/101-rs/issues/66)

slides/A-foundations/composite-types.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,21 @@ fn main() {
144144
}
145145
```
146146

147-
* Note: an enum always is as large as the largest variant
147+
* An enum always is as large as the largest variant + tag
148148

149-
<!--<div class="relative">-->
150-
151-
<div style="margin-left:auto; margin-right:auto; display:block; width:50%;">
149+
<div style="margin-left:auto; margin-right:auto; display:block; width:100%;">
152150

153151
<LightOrDark>
154152
<template #dark>
155-
<center>
153+
<div style="padding: 20px; background-color:#1b1b1b; border-radius: var(--slidev-code-radius) !important;">
156154
<img src="/images/A2-enum-memory-dark.svg"/>
157-
</center>
155+
</div>
158156
</template>
159157
<template #light>
160-
<img src="/images/A2-enum-memory-light.svg"/>
158+
<div style="padding: 20px; background-color:#F8F8F8; border-radius: var(--slidev-code-radius) !important;">
159+
<img src="/images/A2-enum-memory-light.svg"/>
160+
</div>
161161
</template>
162162
</LightOrDark>
163163

164164
</div>
165-
166-
<!--</div>-->

slides/A-foundations/entry.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ theme: default
33
class: text-center
44
highlighter: shiki
55
lineNumbers: true
6-
info: "Rust - A1: Language basics"
6+
info: "Rust - A: Foundation"
77
drawings:
88
persist: false
99
fonts:
1010
mono: Fira Mono
1111
layout: cover
12-
title: "Rust - A1: Language basics"
12+
title: "Rust - A: Foundation"
1313
---
1414

1515
# Rust programming

slides/A-foundations/images

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../images

slides/A-foundations/impl-blocks.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
12
---
23

3-
# Intermission: Impl blocks
4-
In the past few slides we saw a syntax which wasn't explained before:
4+
# `impl` blocks
5+
To associate functions to `structs` and `enums`, we use `impl` blocks
56

67
```rust {3}
78
fn main() {
@@ -17,7 +18,7 @@ fn main() {
1718

1819
---
1920

20-
# Intermission: Impl blocks
21+
# `impl` blocks
2122

2223
```rust {all|6,13|7-12|7|17}
2324
enum IpAddress {
@@ -50,7 +51,7 @@ fn main() {
5051

5152
---
5253

53-
# Intermission: Impl blocks, self and Self
54+
# `self` and `Self`
5455

5556
- The `self` parameter defines how the method can be used.
5657
- The `Self` type is a shorthand for the type on which the current
@@ -60,35 +61,35 @@ fn main() {
6061
struct Foo(i32);
6162

6263
impl Foo {
63-
fn consume(self) -> Self {
64+
fn consume(self) -> Self { // Takes `Foo` by value, returns `Foo`
6465
Self(self.0 + 1)
6566
}
6667

67-
fn borrow(&self) -> &i32 {
68+
fn borrow(&self) -> &i32 { // Takes immutable reference of `Foo`
6869
&self.0
6970
}
7071

71-
fn borrow_mut(&mut self) -> &mut i32 {
72+
fn borrow_mut(&mut self) -> &mut i32 { // Takes mutable reference of `Foo`
7273
&mut self.0
7374
}
7475

75-
fn new() -> Self {
76+
fn new() -> Self { // Associated function, returns `Foo`
7677
Self(0)
7778
}
7879
}
7980
```
8081

8182
---
8283

83-
# Intermission: Impl blocks, the self parameter
84+
# `impl` blocks, the `self` parameter
8485
The self parameter is called the *receiver*.
8586

86-
* The self parameter is always the first and it always has the type on which it
87+
* The `self` parameter is always the first and it always has the type on which it
8788
was defined
88-
* We never specify the type of the self parameter
89-
* We can optionally prepend `&` or `&mut ` to self to indicate that we take
89+
* We never specify the type of the `self` parameter
90+
* We can optionally prepend `&` or `&mut ` to `self` to indicate that we take
9091
a value by reference
91-
* Absence of a self parameter means that the function is an associated function
92+
* Absence of a `self` parameter means that the function is an associated function
9293
instead
9394

9495
```rust
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
---
3+
4+
# To do:
5+
6+
Issue: [tweedegolf/101-rs#67](https://github.com/tweedegolf/101-rs/issues/67)

slides/A-foundations/move-semantics.md

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ we need them somewhere else
1919

2020
</Transform>
2121

22-
23-
---
24-
layout: section
25-
---
26-
# Rust's ownership model
27-
2822
---
2923
layout: default
3024
---
@@ -86,7 +80,7 @@ pointer (to the current stack frame) is decreased.
8680
There are two mechanisms at play here, generally known as the stack and the heap
8781

8882
<div class="grid grid-cols-2">
89-
<div class="flex flex-col rounded-md p-1 bg-teal-100 text-center w-md h-250px">
83+
<div class="flex flex-col rounded-md p-1 bg-teal-100 text-center w-md h-300px">
9084
<div class="bg-red-100 rounded-t-md flex flex-col">
9185
<div class="bg-red-200 rounded-t-md p-1 border-red-500 border">Frame 1</div>
9286
<div class="bg-red-200 p-1 border-red-500 border border-t-0">Frame 2</div>

slides/A-foundations/optionals-errors.md

+39
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
2+
---
3+
4+
# Generics
5+
Structs become even more powerful if we introduce a little of generics
6+
7+
```rust
8+
struct PointFloat(f64, f64);
9+
struct PointInt(i64, i64);
10+
```
11+
12+
We are repeating ourselves here, what if we could write a data structure for
13+
both of these cases?
14+
15+
<v-click>
16+
17+
```rust
18+
struct Point<T>(T, T);
19+
20+
fn main() {
21+
let float_point: Point<f64> = Point(10.0, 10.0);
22+
let int_point: Point<i64> = Point(10, 10);
23+
}
24+
```
25+
26+
Generics are much more powerful, but this is all we need for now
27+
28+
</v-click>
29+
30+
<!--
31+
* The upper case letter between the angled brackets introduces a generic type
32+
parameter.
33+
* We can now use that generic type variable we introduced as a type name
34+
* Then at the point of using the type we can specify which actual type we
35+
want to use
36+
* Generics are much more powerful, but this is enough for now
37+
-->
38+
39+
140
---
241

342
# Option

slides/A-foundations/ownership-borrowing.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ hello, world
154154

155155
# Rules for borrowing and references
156156

157-
- You may only ever have one mutable reference at the same time
158-
- You may have any number of immutable references at the same time as long as
159-
there is no mutable reference
157+
- You may only ever have **one mutable reference** at the same time
158+
- You may have **any number of immutable references** at the same time **as long as
159+
there is no mutable reference**
160160
- References cannot *live* longer than their owners
161-
- A reference will always at all times point to a valid value
161+
- A reference will always at all times *point to a valid value*
162162

163-
These rules are enforced by the Rust compiler.
163+
These rules are enforced by Rust's borrow checker.
164164

165165
<!--
166166
- Rust tries to be smart about enforcing these rules, such that you don't notice

0 commit comments

Comments
 (0)