Fundamentals8 / 42
Up next

Casting with as

fn main() {
    let x = 3.99_f64;
    // truncates toward zero -> 3
    let y = x as i32;
    // narrows to a byte
    let z = y as u8;
    println!("{y} {z}");
}
What you're solving

convert between numeric types