Skip to content

Commit f82276d

Browse files
committed
reference: improve examples of the different array types
1 parent 912ab64 commit f82276d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/doc/reference.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,12 +3344,17 @@ heap.
33443344
A slice is a 'view' into an array. It doesn't own the data it points
33453345
to, it borrows it.
33463346

3347-
An example of each kind:
3347+
Examples:
33483348

33493349
```{rust}
3350-
let vec: Vec<i32> = vec![1, 2, 3];
3351-
let arr: [i32; 3] = [1, 2, 3];
3352-
let s: &[i32] = &vec[..];
3350+
// A stack-allocated array
3351+
let array: [i32; 3] = [1, 2, 3];
3352+
3353+
// A heap-allocated array
3354+
let vector: Vec<i32> = vec![1, 2, 3];
3355+
3356+
// A slice into an array
3357+
let slice: &[i32] = &vector[..];
33533358
```
33543359

33553360
As you can see, the `vec!` macro allows you to create a `Vec<T>` easily. The

0 commit comments

Comments
 (0)