diff --git a/src/SUMMARY.md b/src/SUMMARY.md index d2a9380b6..d599c679b 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -82,8 +82,8 @@ - [`Box` Points to Data on the Heap and Has a Known Size](ch15-01-box.md) - [The `Deref` Trait Allows Access to the Data Through a Reference](ch15-02-deref.md) - [The `Drop` Trait Runs Code on Cleanup](ch15-03-drop.md) - - [The Reference Counted Smart Pointer `Rc`](ch15-04-rc.md) - - [The Interior Mutability Pattern and `RefCell`](ch15-05-interior-mutability.md) + - [`Rc`, the Reference Counted Smart Pointer](ch15-04-rc.md) + - [`RefCell` and the Interior Mutability Pattern](ch15-05-interior-mutability.md) - [Creating Reference Cycles and Leaking Memory is Safe](ch15-06-reference-cycles.md) - [Concurrency](ch16-00-concurrency.md) diff --git a/src/ch15-04-rc.md b/src/ch15-04-rc.md index 04b87c079..ab54f6ca8 100644 --- a/src/ch15-04-rc.md +++ b/src/ch15-04-rc.md @@ -1,4 +1,4 @@ -## The Reference Counted Smart Pointer `Rc` +## `Rc`, the Reference Counted Smart Pointer In the majority of cases, ownership is very clear: you know exactly which variable owns a given value. However, this isn't always the case; sometimes, diff --git a/src/ch15-05-interior-mutability.md b/src/ch15-05-interior-mutability.md index 2ffbe2329..87f794e3c 100644 --- a/src/ch15-05-interior-mutability.md +++ b/src/ch15-05-interior-mutability.md @@ -1,4 +1,4 @@ -## The Interior Mutability Pattern and `RefCell` +## `RefCell` and the Interior Mutability Pattern *Interior mutability* is a design pattern in Rust for allowing you to mutate data that's immutable. The interior mutability pattern involves using `unsafe` @@ -152,6 +152,8 @@ enforce them at runtime instead of compile time. You could choose to use production rather than during development). Also, checking the borrowing rules while your program is running has a performance penalty. +### Multiple Owners of Mutable Data by Combining `Rc` and `RefCell` + So why would we choose to make the tradeoffs that using `RefCell` involves? Well, remember when we said that `Rc` has to store immutable data? Given that `RefCell` is immutable, but has interior mutability, we can combine