-
Notifications
You must be signed in to change notification settings - Fork 142
Description
It should be possible to add a method to Unalign which allows updating or operating in-place by doing the following:
- Copy the inner
Tinto the local stack frame - Call a user-provided callback with a reference to the stack-local
T - Move the now-maybe-modified
Tback to the original memory location (do this even if the callback panics - it must leave the stack-local in a valid state)
We would likely want one method for mutation (takes a &mut self and the callback operates on a &mut T) and one for non-mutation (&self and &T).
For the &self method, we would need to provide it only on Unalign<Cell<T>>, and could likely piggy-back on #211. It may also make sense to just omit a &self method entirely and let users transpose into Cell<Unalign<T>> on their own and then write the same (very straightforward) code we would have.
This would be expensive for large types, but we could just call that out in the documentation.
One caveat: Do we have to worry about pinning/self-referential types (whose memory address is a safety property)?