This commit is contained in:
krahets
2024-05-15 19:00:27 +08:00
parent bd54cd096b
commit e434a3343c
36 changed files with 402 additions and 107 deletions
@@ -99,7 +99,12 @@ Arrays can be initialized in two ways depending on the needs: either without ini
```rust title="array.rs"
/* Initialize array */
let arr: Vec<i32> = vec![0; 5]; // [0, 0, 0, 0, 0]
let arr: [i32; 5] = [0; 5]; // [0, 0, 0, 0, 0]
let slice: &[i32] = &[0; 5];
// In Rust, specifying the length ([i32; 5]) denotes an array, while not specifying it (&[i32]) denotes a slice.
// Since Rust's arrays are designed to have compile-time fixed length, only constants can be used to specify the length.
// Vectors are generally used as dynamic arrays in Rust.
// For convenience in implementing the extend() method, the vector will be considered as an array here.
let nums: Vec<i32> = vec![1, 3, 2, 5, 4];
```