Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Design Patterns and Best Practices in Rust
  • Table Of Contents Toc
Design Patterns and Best Practices in Rust

Design Patterns and Best Practices in Rust

By : Evan Williams
close
close
Design Patterns and Best Practices in Rust

Design Patterns and Best Practices in Rust

By: Evan Williams

Overview of this book

Many Rust developers run into problems when they try to apply familiar object-oriented or cross-language patterns to Rust projects. These mismatches often lead to confusing compiler errors, awkward workarounds, or brittle code. This book helps you avoid those traps by thinking in Rust and applying idiomatic design patterns that embrace ownership, borrowing, and type safety. The book begins with anti-patterns and common mistakes Rust developers often encounter, including misusing object-oriented thinking, over-relying on Clone, or treating the borrow checker as an obstacle. From there, you’ll explore how to rethink traditional design solutions for Rust, including creational, structural, and behavioral design patterns. You’ll also dive into architectural strategies, type-driven design, and Rust-specific techniques such as TypeState. The final chapter brings these ideas together into a design mindset rooted in idiomatic Rust. By the end of this book, you’ll know how to avoid costly mistakes, apply effective patterns confidently, and design Rust applications that are clean, scalable, and reliable. *Email sign-up and proof of purchase required
Table of Contents (20 chapters)
close
close
Lock Free Chapter
1
Part 1: Thinking in Rust
6
Part 2: Replacing Traditional Design Patterns
11
Part 3: New Patterns for Rust
19
Index

Summary

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...

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Design Patterns and Best Practices in Rust
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon