-
Book Overview & Buying
-
Table Of Contents
Design Patterns and Best Practices in Rust
By :
In this chapter, we looked at fighting the borrow checker, and we talked about some common ways that developers try to do that, using our Bad Calculator project to illustrate these approaches and to explore alternatives.
First, we explored why developers want to avoid the borrow checker, and how efforts to do so frequently turn out not to be as simple or helpful as they first appear.
Then we talked about trying to use unsafe code to get around borrow checking, but that this can lead to danger and really doesn't buy us much. We saw that, except in specific circumstances, unsafe code rarely solves ownership problems effectively.
Finally, we talked about trying to avoid thinking about data flows and ownership by creating static globals. We saw how this seems like it would simplify everything, but that it can have a price later in complexity and flexibility. We learned that, typically, global state creates more problems than it solves.
We saw how each of these...