WeCodeAcademy

Rust Data Types

ExampleRust
fn main() {
    let a: i32 = -42;        // signed 32-bit
    let b: u8 = 255;         // unsigned 8-bit
    let c: f64 = 3.14;
    let d: bool = true;
    let e: char = 'R';
    println!("{} {} {} {} {}", a, b, c, d, e);

    let tuple: (i32, &str) = (7, "seven");
    println!("{} {}", tuple.0, tuple.1);

    let arr = [1, 2, 3];
    println!("{} {:?}", arr.len(), arr);

    println!("{}", 17 / 5);
    println!("{}", 17.0 / 5.0);
    println!("{}", 17 % 5);
    println!("{}", u8::MAX);
}
Output
-42 255 3.14 true R
7 seven
3 [1, 2, 3]
3
3.4
2
255

Rust has many integer types: i8..i128 (signed) and u8..u128 (unsigned). If you do not choose, whole numbers default to i32 and decimals to f64.

Quick check

Which type is an unsigned 8-bit integer?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.