Re:Moving to a provenance-aware memory object model for C: p...
by Ar-Curunir on Sunday April 14, 2019 @01:04PM
(#19660443)
The compiler ensures that you can only take one &mut reference at a time. You can have as many immutable `&` references as you want, because you can't change anything through those references (unless you do some unsafe trickery)
[ Parent
| on HN ]
Re:Moving to a provenance-aware memory object model for C: p...
by cesarb on Sunday April 14, 2019 @03:30PM
(#19661194)
> you can only take one &mut reference at a time. You can have as many immutable `&` references as you want
There's another small detail: these two cases are mutually exclusive. You can either have one &mut reference, or as many & references as you want. This means that code receiving a & reference can be sure the object won't change, and that code receiving a &mut reference knows the object can be modified safely since nothing else could be looking at it. (Assuming the object doesn't contain a Cell, the rules are a bit different when a Cell is involved.)