Puzzle 8Walks Like a Duck, Quacks Like a Duck
 fn​ ​double_it​(n: u64, _: i32) ​->​ u64 {
  n * 2
 }
 
 fn​ ​main​() {
 let​ one: i32 = 1;
 let​ n = ​double_it​(one ​as​ _, 3);
  println!(​"{}"​, n);
 }

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

The program will display the following output, showing no warnings or errors:

 2
images/hline.png

Discussion

We find two surprises:

  • You can name a function parameter ...

Get Rust Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.