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

Exercises

  1. Use rustc -O to generate optimized LLVM IR code. What happened to your code?

Solution: With rustc -O, quite a lot of boilerplate code vanishes. But also potentially useful things get lost in optimization, such as integer overflow checks.

  1. Make a new String value in main and see what kind of IR code gets generated.

Solution: There are heap allocations for String.

  1. Add a println! macro to your code. How did it affect the IR code?

Solution: The println! macro adds quite a lot of IR code due to formatting and console output.

  1. Take your second favorite programming language and try to figure out if ownership of variables plays any part. Perhaps behind the curtain, hidden?

Solution: C allocates everything in the stack by default, ...

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