- Mastering Rust
- Rahul Sharma Vesa Kaihlavirta
- 142字
- 2021-07-02 13:35:17
Arrays
Arrays have a fixed length that can store items of the same type. They are denoted by [T, N], where T is any type and N is the number of elements in array. The size of the array cannot be a variable, but has to be a literal usize value:
// arrays.rs
fn main() {
let numbers: [u8; 10] = [1, 2, 3, 4, 5, 7, 8, 9, 10, 11];
let floats = [0.1f64, 0.2, 0.3];
println!("Number: {}", numbers[5]);
println!("Float: {}", floats[2]);
}
In the preceding code, we declared an array, numbers, which contains 10 elements for which we specified the type on the left. In the second array, floats, we specified the type as a suffix to the first item of the array, that is, 0.1f64. This is another way to specify types. Next, let's look at tuples.
推薦閱讀
- HornetQ Messaging Developer’s Guide
- Xamarin.Forms Projects
- 零基礎學Python網絡爬蟲案例實戰全流程詳解(高級進階篇)
- JavaScript入門經典
- Python深度學習:基于TensorFlow
- C語言程序設計教程
- Microsoft Azure Storage Essentials
- 速學Python:程序設計從入門到進階
- Learning Node.js for .NET Developers
- Node.js開發指南
- Vue.js應用測試
- 機器學習微積分一本通(Python版)
- Java 9 Programming By Example
- Exploring SE for Android
- 寫給青少年的人工智能(Python版·微課視頻版)