Compile-time checks are not the only place where you can benefit from a performance enhancement at no cost. While in Chapter 1, Common Performance Pitfalls, we saw the common errors people write in Rust, we left the most advanced tips and tricks for this chapter.
Extra performance tips
Using closures to avoid runtime evaluation
Sometimes, it might seem natural to write code that does not perform as fast as expected. Many times, this is due to Rust doing some extra computations at runtime. An example of an unnecessary computation that someone could write is the following:
let opt = Some(123);
let non_opt = opt.unwrap_or(some_complex_function());
I have intentionally made this example simply because a real...