- 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.
推薦閱讀
- C++案例趣學
- Python機器學習:數據分析與評分卡建模(微課版)
- ThinkPHP 5實戰
- 編程數學
- Android開發:從0到1 (清華開發者書庫)
- Python深度學習原理、算法與案例
- 移動互聯網軟件開發實驗指導
- Illustrator CC平面設計實戰從入門到精通(視頻自學全彩版)
- SQL Server 2016 從入門到實戰(視頻教學版)
- Qlik Sense? Cookbook
- 軟件測試項目實戰之功能測試篇
- SAP HANA Cookbook
- Web前端開發全程實戰:HTML5+CSS3+JavaScript+jQuery+Bootstrap
- 軟件定義存儲:原理、實踐與生態
- 微軟辦公軟件認證考試MOS Access 2013實訓教程