9 Immutability

 

This chapter covers

  • Understanding the benefits of immutability
  • Thinking in terms of immutable data and how it works in Rust
  • Using traits to make nearly anything immutable
  • Exploring crates that provide immutable data structures

Immutability is a powerful concept that can help everyone build better software. Immutability as it relates to writing software is the idea that after a value has been declared and assigned, it cannot be modified (or mutated). Contrast this concept with mutability, in which a value can be altered after it has been declared. In other words, values that can be changed are mutable, and values that are never changed are immutable.

Immutability is an important design pattern—and one of the most underloved and underappreciated ones at that. I feel that this pattern is so valuable, however, that I’m dedicating a chapter of this book to the subject, although it deserves an entire book. I won’t be able to go into as much depth in this chapter as I’d like, but I’ll leave you with a great starting point to explore the topic further.

9.1 The benefits of immutability

 
 
 

9.2 Why immutability is not a magic bullet

 
 

9.3 How to think about immutable data

 
 
 

9.4 Understanding immutability in Rust

 
 
 

9.5 Reviewing the basics of immutability in Rust

 
 
 
 

9.6 Using traits to make (almost) anything immutable

 
 

9.7 Using Cow for immutability

 
 

9.8 Using crates for immutable data structures

 
 
 

9.8.1 Using im

 
 
 
 

9.8.2 Using rpds

 

Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest