mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-29 03:27:44 +00:00
Rollup merge of #26789 - tshepang:improve-array-examples, r=alexcrichton
This commit is contained in:
commit
8b51b8f181
@ -3351,12 +3351,17 @@ heap.
|
|||||||
A slice is a 'view' into an array. It doesn't own the data it points
|
A slice is a 'view' into an array. It doesn't own the data it points
|
||||||
to, it borrows it.
|
to, it borrows it.
|
||||||
|
|
||||||
An example of each kind:
|
Examples:
|
||||||
|
|
||||||
```{rust}
|
```{rust}
|
||||||
let vec: Vec<i32> = vec![1, 2, 3];
|
// A stack-allocated array
|
||||||
let arr: [i32; 3] = [1, 2, 3];
|
let array: [i32; 3] = [1, 2, 3];
|
||||||
let s: &[i32] = &vec[..];
|
|
||||||
|
// A heap-allocated array
|
||||||
|
let vector: Vec<i32> = vec![1, 2, 3];
|
||||||
|
|
||||||
|
// A slice into an array
|
||||||
|
let slice: &[i32] = &vector[..];
|
||||||
```
|
```
|
||||||
|
|
||||||
As you can see, the `vec!` macro allows you to create a `Vec<T>` easily. The
|
As you can see, the `vec!` macro allows you to create a `Vec<T>` easily. The
|
||||||
|
Loading…
Reference in New Issue
Block a user