Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joshlf opened this issue Jul 29, 2023 · 0 comments · Fixed by #212
Closed

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

joshlf opened this issue Jul 29, 2023 · 0 comments · Fixed by #212

Comments

@joshlf
Copy link
Member

joshlf commented Jul 29, 2023

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)?

@joshlf joshlf changed the title Add ability to update Unalign in-place Add ability to update or operate on an Unalign in-place Jul 29, 2023
joshlf added a commit that referenced this issue Aug 1, 2023
Adds the `Unalign::update` method, which allows updating an `Unalign`
in-place via a callback. This works by temporarily moving the `Unalign`
into the local stack frame in order to call the callback.

Closes #206
joshlf added a commit that referenced this issue Aug 1, 2023
Adds the `Unalign::update` method, which allows updating an `Unalign`
in-place via a callback. This works by temporarily moving the `Unalign`
into the local stack frame in order to call the callback.

Closes #206
joshlf added a commit that referenced this issue Aug 1, 2023
Adds the `Unalign::update` method, which allows updating an `Unalign`
in-place via a callback. This works by temporarily moving the `Unalign`
into the local stack frame in order to call the callback.

Closes #206
joshlf added a commit that referenced this issue Aug 3, 2023
Adds the `Unalign::update` method, which allows updating an `Unalign`
in-place via a callback. This works by temporarily moving the `Unalign`
into the local stack frame in order to call the callback.

Closes #206
joshlf added a commit that referenced this issue Aug 3, 2023
Adds the `Unalign::update` method, which allows updating an `Unalign`
in-place via a callback. This works by temporarily moving the `Unalign`
into the local stack frame in order to call the callback.

Closes #206
joshlf added a commit that referenced this issue Aug 3, 2023
Adds the `Unalign::update` method, which allows updating an `Unalign`
in-place via a callback. This works by temporarily moving the `Unalign`
into the local stack frame in order to call the callback.

Closes #206
@joshlf joshlf mentioned this issue Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant