Rust 程式設計視訊教程對應講解內容-型別

linghuyichong發表於2019-12-19

頭條地址:https://www.ixigua.com/i676544267458235648...
B站地址:https://www.bilibili.com/video/av78062009?...
網易雲課堂地址:https://study.163.com/course/introduction....

use std::usize;
fn show(arr: [u32; 3]) {
    for i in &arr {
        println!("{}", i);
    }
}

fn main() {
    //bool
    let is_ok: bool = true;
    let is_error = false;
    println!("is_ok = {}", is_ok);
    println!("is_error = {}", is_error);

    //char 特別注意,rust char型別佔32位,可以是一個漢字
    let he: char = '你';
    println!("he is {}", he);

    //數字型別: i8, i16, i32, i64, u8, u16, u32, u64, f32, f64
    let a: i8 = 1;
    let b: f32 = 0.0008;
    println!("a = {}", a);
    println!("b = {}", b);

    //自適應型別isize, usize
    println!("max = {}", usize::max_value());

    //陣列
    //定義:[Type; size]
    let a: [u32; 3] = [1, 2, 3];
    //let b: [u32; 4] = [1, 2, 3, 4];
    println!("a[1] == {}", a[1]);
    show(a);
    //show(b);

    //元組
    //let tup: (i32, f32, u32) = (500, 0.6, 11);
    let tup = (500, 0.6, 11);
    println!("0 = {}", tup.0);
    println!("1 = {}", tup.1);
    println!("2 = {}", tup.2);

    let (x, y, z) = tup;
    println!("x = {}", x);
    println!("y = {}", y);
    println!("z = {}", z);

    println!("Hello, world!");
}

令狐一衝

相關文章