- 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.
推薦閱讀
- CMDB分步構建指南
- Vue.js前端開發基礎與項目實戰
- Learning Elixir
- C/C++常用算法手冊(第3版)
- 零基礎學MQL:基于EA的自動化交易編程
- STM32F0實戰:基于HAL庫開發
- 從零開始學C#
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- Instant Automapper
- Learning Kotlin by building Android Applications
- The Statistics and Calculus with Python Workshop
- PHP項目開發全程實錄(第4版)
- Python編程基礎教程
- Python 3快速入門與實戰
- Python Social Media Analytics