- Learning Rust
- Paul Johnson Vesa Kaihlavirta
- 165字
- 2021-07-02 23:07:18
Arrays
Arrays are simple to construct. For example:
let my_array = ["Merseybus", "Amberline", "Crosville", "Liverbus", "Liverline", "Fareway"];
Arrays must comply with a number of rules, which are as follows:
- The array has a fixed size. It can never grow as it is stored as a continuous memory block.
- The contents of the array can only ever be of one type.
As with any type of variable, by default arrays are non-mutable. Even if the array is mutable, the overall size cannot be changed. For example, if an array has five elements, it cannot be changed to six.
We can also create an array with a type, as follows:
let mut my_array_two: [i32; 4] = [1, 11, 111, 1111]; let mut empty_array: [&str; 0] = [];
It is also possible to create an array a number of times with the same value, as follows:
let number = [111; 5];
This will create an array called number with 5 elements, all initialized to a value of 111.
推薦閱讀
- 單片機C語言程序設計實訓100例:基于STC8051+Proteus仿真與實戰
- QGIS:Becoming a GIS Power User
- HDInsight Essentials(Second Edition)
- Mockito Essentials
- Tableau Dashboard Cookbook
- Oracle Database XE 11gR2 Jump Start Guide
- Android技術內幕(系統卷)
- ANSYS FLUENT 16.0超級學習手冊
- Managing Windows Servers with Chef
- HTML5 Game Development by Example:Beginner's Guide(Second Edition)
- Pandas入門與實戰應用:基于Python的數據分析與處理
- Python程序設計
- Java與Android移動應用開發:技術、方法與實踐
- Java語言GUI程序設計
- jQuery權威指南