The Complete Rust Programming Course

1. Installing Rust

2. The Basics

1. About This Section

3. Hello, World!

cargo new hello
fn main() {
    println!("Hello, world!");
}

4. More about Visual Studio Code

5. Variables and Mutability

cargo new variables
cargo build
cargo run
fn main() {
    let mut x = 5;

    println!("the value of x is {}", x);

    x = 6; // cannot assign twice to immutable variable -> let mut 变成可变
    println!("the value of x is {}", x);

    const SECONDS: i8 = 60; // cannot be mutable 
    println!("the value of SECONDS is {}", SECONDS);
}

6. Scalar Data Types

cargo new data_types
fn main() {
    let x: i8 = 10;
    println!("{}", x);

    // 无符号, 始终为正数
    let _y: u8 = 10; // 编译器警告, 定义了但是没使用, 可以给变量前面加个 _

    // 不同进制
    let decimal = 02_55; // 255, _ 用来分隔字符
    let hex = 0xff;
    let octal = 0o377;
    let binary = 0b1111_1111;
    print!("{},{},{},{}", decimal, hex, octal, binary);

    let byte = b'A';
    println!("{}", byte);

    let x = 2.0;
    let y: f32 = 1.0;

    let t = true;
    let f: bool = false;

    let c = 'c';
    println!("{}", c);

    // + - * /
    let a = 10;
    let b = 4;

    let remainder = a % b;
    println!("{}", remainder);
}

7. Tuples


  目录