Tsallaka zuwa abun ciki
Justice Tech School

Rust Data Types

Scalar types: integers (i8 to i128, u8 to u128, isize, usize), floats (f32, f64), bool and char. Rust has no implicit conversion, so use as or From.

Example
let a: i32 = -42;
let b: u8 = 255;
let c: f64 = 2.5;
let d = 'R';
let e = true;
println!("{} {} {} {} {}", a, b, c, d, e);
println!("{}", a as f64 + c);

Result

-42 255 2.5 R true
-39.5

Exercise

Convert with as.

a  f64

Quiz Test

Does Rust convert i32 to f64 implicitly?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.