-
Book Overview & Buying
-
Table Of Contents
Design Patterns and Best Practices in Rust
By :
In this chapter, we explored three common anti-patterns in Rust. We talked about how it is tempting to avoid thinking about ownership concerns, and we saw the importance of working with Rust's ownership system rather than against it. Then, we discussed the very common issue of overusing clone and why it is often a sign of design issues. Finally, we discussed the equally common practice of misusing smart pointers such as Rc and RefCell, and we discussed how to know when smart pointers are appropriate and when they're being misused.
We also examined how our calculator project could be implemented using these anti-patterns, and then showed how to refactor it to use more idiomatic Rust patterns.
In the next chapter, we'll explore a related but distinct anti-pattern: fighting with the borrow checker. While this chapter focused on techniques that circumvent ownership rules, the next chapter examines what happens when developers try to outsmart the borrow checker...