Commit d4ea311
authored
Idiomatic: Rework Option-in-Drop example to emphasize move semantics (#3168)
Rework the example in the "Drop: Option" slide to emphasize how `Option`
is used to achieve move operations in `Drop` code. The current version
of the slide emphasizes the wrong thing in my opinion, and fails to
actually demonstrate the pattern of needing to perform a move operation
in `drop`. I've modified `Handle` to have a `fn close(self)` instead of
a `Drop` impl, that way `File::drop` needs to move out of its inner
field in order to call `close`.1 parent 2d930f2 commit d4ea311
1 file changed
Lines changed: 14 additions & 22 deletions
Lines changed: 14 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | 30 | | |
33 | 31 | | |
34 | 32 | | |
35 | 33 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 34 | + | |
| 35 | + | |
39 | 36 | | |
40 | 37 | | |
41 | 38 | | |
42 | 39 | | |
43 | 40 | | |
44 | 41 | | |
45 | | - | |
46 | | - | |
47 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
53 | 51 | | |
54 | | - | |
55 | 52 | | |
56 | 53 | | |
57 | 54 | | |
58 | 55 | | |
59 | 56 | | |
60 | 57 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
70 | 62 | | |
71 | | - | |
72 | | - | |
| 63 | + | |
| 64 | + | |
73 | 65 | | |
74 | 66 | | |
75 | 67 | | |
| |||
0 commit comments