Skip to content

Add ability to update or operate on an Unalign in-place #206

@joshlf

Description

@joshlf

It should be possible to add a method to Unalign which allows updating or operating in-place by doing the following:

  • Copy the inner T into the local stack frame
  • Call a user-provided callback with a reference to the stack-local T
  • Move the now-maybe-modified T back 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)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions