Files
rust-by-example/src/types.rs
2024-08-13 08:54:05 +02:00

21 lines
558 B
Rust

pub fn types_module() {
// casting with as: types can be casted as long as the types overlap.
let decimal = 65.4321;
let integer: u8 = decimal as u8;
println!("The decimal {} is casted to the u8 {}", decimal, integer);
// dangerous carting can be done with some methods
unsafe {
println!(
"f32 -100.0 as u8 is : {}",
(-100.0_f32).to_int_unchecked::<u8>()
);
}
// type alias are also a thing
type Inch = u64;
let inch: Inch = 5;
println!("using type aliases {}", inch);
}