feat(arrived at types)
This commit is contained in:
20
src/types.rs
Normal file
20
src/types.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user