typestar

Scalar types and casts in Rust

Rust's sized integers, floats, bools, and chars.

fn main() {
    let byte: u8 = 255;
    let big: i64 = 9_000_000_000;
    let pi = 3.14159_f64;
    let yes = true;
    let letter = 'R';

    let widened = byte as i64 + big;
    let truncated = pi as i32;
    let flag = yes as u8;
    println!("{widened} {truncated} {flag} {letter}");
}

How it works

  1. Types like u8 and i64 state width and sign.
  2. as casts between numeric types explicitly.
  3. A char is a full Unicode scalar.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
253
Tokens
66
Three-star pace
80 tpm

At the three-star pace of 80 tokens a minute, this run takes about 50 seconds.

Type this snippet

Step 3 of 6 in Variables & types, step 3 of 39 in Language basics.

← Previous Next →