Puzzle 9Out of Order
 fn​ ​main​() {
 let​ ​mut​ floats = vec![3.1, 1.2, 4.5, 0.3];
  floats​.sort​();
 
  println!(​"{:#?}"​, floats);
 }

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 fail to compile, and you’ll receive the following error message:

 the trait `Ord` is not implemented for `{float}`
images/hline.png

Discussion

Rust makes it easy to sort vectors of most types. A vector’s ...

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.