Puzzle 3 | Type Conversion |
| fn main() { |
| let x : u64 = 4_294_967_296; |
| let y = x as u32; |
| if x == y as u64 { |
| println!("x equals y."); |
| } else { |
| println!("x does not equal y."); |
| } |
| } |
Guess the Output | |
---|---|
Try to guess what the output is before moving to the next page. |
The program will display the following output:
| x does not equal y. |
Discussion
Rust’s as keyword is lossy. And when you use it to convert ...
Get Rust Brain Teasers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.