@@ -118,7 +118,8 @@ These types are _generally_ found in struct fields, but they may be found elsewh
118118
119119## ` Cell<T> `
120120
121- [ ` Cell<T> ` ] [ cell ] is a type that provides zero-cost interior mutability, but only for ` Copy ` types.
121+ [ ` Cell<T> ` ] [ cell ] is a type that provides zero-cost interior mutability by moving data in and
122+ out of the cell.
122123Since the compiler knows that all the data owned by the contained value is on the stack, there's
123124no worry of leaking any data behind references (or worse!) by simply replacing the data.
124125
@@ -160,24 +161,25 @@ This relaxes the “no aliasing with mutability” restriction in places
160161unnecessary. However, this also relaxes the guarantees that the restriction provides; so if your
161162invariants depend on data stored within ` Cell ` , you should be careful.
162163
163- This is useful for mutating primitives and other ` Copy ` types when there is no easy way of
164+ This is useful for mutating primitives and other types when there is no easy way of
164165doing it in line with the static rules of ` & ` and ` &mut ` .
165166
166167` Cell ` does not let you obtain interior references to the data, which makes it safe to freely
167168mutate.
168169
169170#### Cost
170171
171- There is no runtime cost to using ` Cell<T> ` , however if you are using it to wrap larger ( ` Copy ` )
172+ There is no runtime cost to using ` Cell<T> ` , however if you are using it to wrap larger
172173structs, it might be worthwhile to instead wrap individual fields in ` Cell<T> ` since each write is
173174otherwise a full copy of the struct.
174175
175176
176177## ` RefCell<T> `
177178
178- [ ` RefCell<T> ` ] [ refcell ] also provides interior mutability, but isn't restricted to ` Copy ` types.
179+ [ ` RefCell<T> ` ] [ refcell ] also provides interior mutability, but doesn't move data in and out of the
180+ cell.
179181
180- Instead , it has a runtime cost. ` RefCell<T> ` enforces the read-write lock pattern at runtime (it's
182+ However , it has a runtime cost. ` RefCell<T> ` enforces the read-write lock pattern at runtime (it's
181183like a single-threaded mutex), unlike ` &T ` /` &mut T ` which do so at compile time. This is done by the
182184` borrow() ` and ` borrow_mut() ` functions, which modify an internal reference count and return smart
183185pointers which can be dereferenced immutably and mutably respectively. The refcount is restored when
0 commit comments