33 lines
421 B
Markdown
33 lines
421 B
Markdown
# Arrays.
|
|
|
|
# Create an array.
|
|
|
|
Specify the type first, then the count.
|
|
|
|
```rust
|
|
let array: [i32; 5] = [1, 2, 3, 4, 5]; // Manual init.
|
|
let array: [i32; 5] = [0; 5]; // All to zeroes.
|
|
```
|
|
|
|
# Get the array size.
|
|
|
|
Use `.len()` method.
|
|
|
|
```rust
|
|
let size = array.len();
|
|
```
|
|
|
|
# Create a slice.
|
|
|
|
## Whole array.
|
|
|
|
```rust
|
|
let slice = &array;
|
|
```
|
|
|
|
## Partial.
|
|
|
|
```rust
|
|
let slice = &array[1..4]; // Slice of: 1, 2, 3.
|
|
```
|