Probably the largest thing Rust lost when moving from sigil-pointers into library pointers is the ability to pattern-match on them, or (more fundamentally) the borrow-checker’s ability to reason about them.
The direct loss of magic-borrowck-ability is merely slightly annoying, but the loss of pattern-matching is rather problematic when working with library-pointer-based data structures.
The primary reason for this loss is that library Deref can execute arbitrary safe code, including modifying the contents in the middle of a match.
This can be fixed, however:
- Introduce a
unsafe trait DerefPure : Deref {}. Behaviour is undefined if the Deref or DerefMut impl of these types is not strongly pure - i.e. calling it zero, one, or more times must have the same effect and return the same result.
- If a type implements
DerefPure, then it behaves like ~ in old Rust - it can be matched by box patterns, and the borrow checker is aware of subfields of it.