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

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

主站蜘蛛池模板: 白城市| 乌拉特中旗| 阳泉市| 长垣县| 化德县| 蓬溪县| 江都市| 寻乌县| 中山市| 西平县| 镇平县| 紫阳县| 沅陵县| 神农架林区| 阳新县| 沧源| 丘北县| 多伦县| 耒阳市| 长武县| 清徐县| 乐安县| 谢通门县| 龙海市| 渝北区| 咸丰县| 湘阴县| 诸城市| 彰化县| 青海省| 瓮安县| 和硕县| 游戏| 竹山县| 贵南县| 开化县| 虞城县| 定边县| 长汀县| 略阳县| 屏南县|