Skip to content

Commit 153e16d

Browse files
committed
Touch up slides, add links to open issues
1 parent 7a2e366 commit 153e16d

20 files changed

+447
-164
lines changed

slides/A-foundations/basic-syntax.md

+31-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2+
---
3+
layout: section
4+
---
5+
6+
# Basic Syntax
7+
18
---
29

310
# Variables
@@ -84,6 +91,7 @@ that variable
8491
```rust
8592
fn main() {
8693
let x: i32 = 20;
94+
// ^^^^^ Type annotation
8795
}
8896
```
8997

@@ -98,7 +106,7 @@ layout: two-cols
98106
# Integers
99107

100108
| Length | Signed | Unsigned |
101-
|---------------|---------|----------|
109+
| ------------- | ------- | -------- |
102110
| 8 bits | `i8` | `u8` |
103111
| 16 bits | `i16` | `u16` |
104112
| 32 bits | `i32` | `u32` |
@@ -242,14 +250,14 @@ then the code for b is not executed
242250

243251
```rust
244252
fn main() {
245-
let c = 'z';
253+
let c: char = 'z';
246254
let z = 'ℤ';
247255
let heart_eyed_cat = '😻';
248256
}
249257
```
250258

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

254262
<!--
255263
- The final scalar type is the character, but it isn't often seen.
@@ -261,16 +269,22 @@ instead.
261269

262270
---
263271

264-
# Strings
272+
# `String`s
265273
```rust
266-
// Owned, heap-allocated string *slice*
267-
let s1: String = String::new("Hello, 🌍!");
274+
275+
let s1 = String::new("Hello, 🌍!");
276+
// ^^^^^^ Owned, heap-allocated string
268277
```
269278

270-
- Rust strings are UTF-8-encoded
279+
- Rust `String`s are UTF-8-encoded
271280
- Unlike C/C++: *Not null-terminated*
272281
- Cannot be indexed like C strings
282+
- `String` is heap-allocated
273283
- Actually many types of strings in Rust
284+
- `CString`
285+
- `PathBuf`
286+
- `OsString`
287+
- ...
274288

275289
<!--
276290
- Rusts strings are complicated, because all strings are complicated
@@ -294,7 +308,7 @@ fn main() {
294308
- Group multiple values into a single compound type
295309
- Fixed size
296310
- Different types per element
297-
- Create a tuple by writing a comma-separated list of values inside parentheses
311+
- Create by writing a comma-separated list of values inside parentheses
298312

299313
::right::
300314

@@ -406,9 +420,9 @@ fn also_returns_nothing() {
406420
```
407421

408422
- The function boundary must always be explicitly annotated with types
409-
- Within the function body type inference may be used
423+
- Type inference may be used in function body
410424
- A function that returns nothing has the return type *unit* (`()`)
411-
- The function body contains a series of statements optionally ending with an
425+
- Function body contains a series of statements optionally ending with an
412426
expression
413427

414428
<!--
@@ -440,6 +454,10 @@ fn my_fun() {
440454
let x = 10;
441455
```
442456

457+
```rust
458+
return 42;
459+
```
460+
443461
<v-click>
444462

445463
```rust
@@ -465,9 +483,9 @@ statements
465483

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

472490
```rust {all|2-5}
473491
fn main() {

slides/A-foundations/closures.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
2+
---
3+
layout: section
4+
---
5+
6+
# Closures
7+
18
---
29
layout: default
310
---
4-
# Intermezzo: Closures
11+
# Closures
512

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

38+
---
39+
40+
# To do
41+
42+
Issue: [tweedegolf/101-rs#66](https://github.com/tweedegolf/101-rs/issues/66)

slides/A-foundations/composite-types.md

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2+
---
3+
layout: section
4+
---
5+
6+
# Composite types
7+
18
---
29

310
# Types redux
@@ -144,23 +151,21 @@ fn main() {
144151
}
145152
```
146153

147-
* Note: an enum always is as large as the largest variant
148-
149-
<!--<div class="relative">-->
154+
* An enum always is as large as the largest variant + tag
150155

151-
<div style="margin-left:auto; margin-right:auto; display:block; width:50%;">
156+
<div style="margin-left:auto; margin-right:auto; display:block; width:100%;">
152157

153158
<LightOrDark>
154159
<template #dark>
155-
<center>
160+
<div style="padding: 20px; background-color:#1b1b1b; border-radius: var(--slidev-code-radius) !important;">
156161
<img src="/images/A2-enum-memory-dark.svg"/>
157-
</center>
162+
</div>
158163
</template>
159164
<template #light>
160-
<img src="/images/A2-enum-memory-light.svg"/>
165+
<div style="padding: 20px; background-color:#F8F8F8; border-radius: var(--slidev-code-radius) !important;">
166+
<img src="/images/A2-enum-memory-light.svg"/>
167+
</div>
161168
</template>
162169
</LightOrDark>
163170

164171
</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/first-project.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2+
---
3+
layout: section
4+
---
5+
# Meeting Rust
6+
17
---
28
layout: default
39
---

slides/A-foundations/images

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

slides/A-foundations/impl-blocks.md

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
2+
---
3+
layout: section
4+
---
5+
6+
# `impl` blocks
7+
18
---
29

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

613
```rust {3}
714
fn main() {
@@ -17,7 +24,7 @@ fn main() {
1724

1825
---
1926

20-
# Intermission: Impl blocks
27+
# `impl` blocks
2128

2229
```rust {all|6,13|7-12|7|17}
2330
enum IpAddress {
@@ -50,7 +57,7 @@ fn main() {
5057

5158
---
5259

53-
# Intermission: Impl blocks, self and Self
60+
# `self` and `Self`
5461

5562
- The `self` parameter defines how the method can be used.
5663
- The `Self` type is a shorthand for the type on which the current
@@ -60,35 +67,35 @@ fn main() {
6067
struct Foo(i32);
6168

6269
impl Foo {
63-
fn consume(self) -> Self {
70+
fn consume(self) -> Self { // Takes `Foo` by value, returns `Foo`
6471
Self(self.0 + 1)
6572
}
6673

67-
fn borrow(&self) -> &i32 {
74+
fn borrow(&self) -> &i32 { // Takes immutable reference of `Foo`
6875
&self.0
6976
}
7077

71-
fn borrow_mut(&mut self) -> &mut i32 {
78+
fn borrow_mut(&mut self) -> &mut i32 { // Takes mutable reference of `Foo`
7279
&mut self.0
7380
}
7481

75-
fn new() -> Self {
82+
fn new() -> Self { // Associated function, returns `Foo`
7683
Self(0)
7784
}
7885
}
7986
```
8087

8188
---
8289

83-
# Intermission: Impl blocks, the self parameter
90+
# `impl` blocks, the `self` parameter
8491
The self parameter is called the *receiver*.
8592

86-
* The self parameter is always the first and it always has the type on which it
93+
* The `self` parameter is always the first and it always has the type on which it
8794
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
95+
* We never specify the type of the `self` parameter
96+
* We can optionally prepend `&` or `&mut ` to `self` to indicate that we take
9097
a value by reference
91-
* Absence of a self parameter means that the function is an associated function
98+
* Absence of a `self` parameter means that the function is an associated function
9299
instead
93100

94101
```rust
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
---
3+
layout: section
4+
---
5+
6+
# Interior mutability
7+
8+
---
9+
10+
# To do:
11+
12+
Issue: [tweedegolf/101-rs#67](https://github.com/tweedegolf/101-rs/issues/67)

0 commit comments

Comments
 (0)