Snakehand•

Thanks, this was a nice overview.

12
pitdickerOP•

If you know any other patterns to use interior mutability safely, please let me know ;-)

6
Ruskyrust•

The section on Cell could use a mention of RFC 1789, which allows indexing operations on Cell<[T]>s to produce places of type Cell<T> or [Cell<T>].

The same thing can be done for structs and their fields, allowing projections from Cell<Struct> to Cell<Field>. There's no way to express this generically in today's type system, the way you can for indexing, but you can do it yourself with unsafe in an ad-hoc way.

9
pitdickerOP•
2
pitdickerOP•

Thank you for the suggestion. Maybe creative methods like these deserve a special post, RefMut::map_split is another one. Maybe I'll find the time...

1
claire_resurgent•

Interior mutability may be accessed through raw pointers too. This is needed to make memory-mapped IO and FFI work correctly.

Pure Rust programs should use UnsafeCell in almost all situations (for clarity if nothing else) but it's not always required.

3
Silly-Freak•

Nice read! Two minor findings : downgrade(&self) should be downgrade(self), and rw2 and rw3 have TCell parameters, should these not be QCells?

5
pitdickerOP•

Thank you for the close read!

2
DoveOfHope•

Thanks for reminding me that OnceCell supports a Lazy<T>, I wasted some time trying to hand-implement that recently.

1