O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise - fixing the tests

  1. Fix the preceding compilation problem.

Solution: Fixed by removing the one semicolon on line 63.

  1. The code has a few other subtle problems, revealed by the tests, fix those too.

Solution: The first one is that the Grid implementation creates a world with only Stone as its ground. Changing it to Soil fixes the test.

The second one is in the generate_empty method. The loop should start from 0, not 1.

  1. After fixing the tests, the compiler warns about dead code. Find out how to suppress those warnings.

Solution: The #[allow(dead_code)] attribute for each enum would fix this. In a real software project, there's usually no reason to keep dead code around, however.

Here's the code that contains all the three fixes: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required