- 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.
推薦閱讀
- Vue.js 3.x快速入門
- DBA攻堅指南:左手Oracle,右手MySQL
- Effective C#:改善C#代碼的50個有效方法(原書第3版)
- 信息可視化的藝術:信息可視化在英國
- C/C++算法從菜鳥到達人
- 實用防銹油配方與制備200例
- MATLAB實用教程
- Learning ArcGIS for Desktop
- 數據結構習題解析與實驗指導
- Mastering Android Game Development
- Internet of Things with ESP8266
- uni-app跨平臺開發與應用從入門到實踐
- Python編程基礎教程
- ROS機器人編程實戰
- Offer來了:Java面試核心知識點精講(框架篇)