-
Book Overview & Buying
-
Table Of Contents
Rust for C++ Developers
By :
New Rust programmers, especially those coming from languages such as C++, often experience a season of frustration as they attempt to get their first programs to pass the compiler's strict validation. This experience is referred to as "fighting the borrow checker," and because of it, Rust is regarded by many to have a significant learning curve.
In this section, we'll look at some patterns that can lead to protracted arguments with the compiler, and how we can avoid them. This isn't to say that any of these patterns is inherently bad, only that it's best to be comfortable with the language before using them.
As we saw earlier, whenever a reference is used inside a structure, we must explicitly specify a lifetime annotation for it. Because the lifetime annotation is considered generic, it becomes part of that structure's type signature. This can lead to a cascading effect where...