File tree Expand file tree Collapse file tree 2 files changed +5
-6
lines changed
exercises/simple-linked-list Expand file tree Collapse file tree 2 files changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ struct Node<T> {
17
17
```
18
18
` data ` contains the stored data, and ` next ` points to the following node (if available) or None.
19
19
20
- ### Why Option<__ Box __ <Node<T >>> and not just Option<Node<T >>?
20
+ ### Why ` Option<Box <Node<T>>> ` and not just ` Option<Node<T>> ` ?
21
21
Try it on your own. You will get the following error.
22
22
23
23
```
@@ -27,8 +27,7 @@ Try it on your own. You will get the following error.
27
27
| next: Option<Node<T>>,
28
28
| --------------------- recursive without indirection
29
29
```
30
-
30
+
31
31
The problem is that at compile time the size of next must be known.
32
32
Since ` next ` is recursive ("a node has a node has a node..."), the compiler does not know how much memory is to be allocated.
33
33
In contrast, [ Box] ( https://doc.rust-lang.org/std/boxed/ ) is a heap pointer with a defined size.
34
-
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ struct Node<T> {
40
40
```
41
41
` data ` contains the stored data, and ` next ` points to the following node (if available) or None.
42
42
43
- ### Why Option<__ Box __ <Node<T >>> and not just Option<Node<T >>?
43
+ ### Why ` Option<Box <Node<T>>> ` and not just ` Option<Node<T>> ` ?
44
44
Try it on your own. You will get the following error.
45
45
46
46
```
@@ -50,11 +50,11 @@ Try it on your own. You will get the following error.
50
50
| next: Option<Node<T>>,
51
51
| --------------------- recursive without indirection
52
52
```
53
-
53
+
54
54
The problem is that at compile time the size of next must be known.
55
55
Since ` next ` is recursive ("a node has a node has a node..."), the compiler does not know how much memory is to be allocated.
56
56
In contrast, [ Box] ( https://doc.rust-lang.org/std/boxed/ ) is a heap pointer with a defined size.
57
-
57
+
58
58
59
59
## Rust Installation
60
60
You can’t perform that action at this time.
0 commit comments