官术网_书友最值得收藏!

  • 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.

主站蜘蛛池模板: 苍溪县| 晋江市| 华亭县| 新乡县| 大厂| 海淀区| 德令哈市| 同德县| 安宁市| 临邑县| 乌拉特后旗| 株洲县| 峡江县| 潞城市| 青岛市| 虹口区| 贡嘎县| 青阳县| 洛隆县| 临猗县| 江阴市| 恩平市| 洛南县| 武功县| 宁强县| 辽中县| 兴城市| 舟山市| 休宁县| 都昌县| 肇州县| 海安县| 库伦旗| 哈巴河县| 新乐市| 富宁县| 天柱县| 仁寿县| 延津县| 西藏| 仲巴县|