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

Allow dereferencing an Unalign, add trait impls #126

Merged
merged 1 commit into from
Nov 10, 2022
Merged

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Nov 7, 2022

Provide methods and trait implementations to generate &T and &mut T from &Unalign<T> and &mut Unalign<T> respectively. If T: Unaligned, then these are infallible. Otherwise, a runtime check must be performed to ensure that the Unalign<T> satisfies T's alignment requirement.

Since dereferencing is now supported, we can also implement various traits using Deref and DerefMut impls.

@joshlf
Copy link
Member Author

joshlf commented Nov 7, 2022

@djkoloski can you take a look at this when you get a chance? Please be brutal about the safety comments. I want to make sure they're 100% bulletproof.

@joshlf joshlf force-pushed the deref-unalign branch 3 times, most recently from ca666e7 to e60bf7f Compare November 8, 2022 05:22
djkoloski
djkoloski previously approved these changes Nov 9, 2022
Copy link
Member

@djkoloski djkoloski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few small changes that could be made (your discretion).

src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
Provide methods and trait implementations to generate `&T` and `&mut T`
from `&Unalign<T>` and `&mut Unalign<T>` respectively. If `T:
Unaligned`, then these are infallible. Otherwise, a runtime check must
be performed to ensure that the `Unalign<T>` satisfies `T`'s alignment
requirement.

Since dereferencing is now supported, we can also implement various
traits using `Deref` and `DerefMut` impls.
@joshlf
Copy link
Member Author

joshlf commented Nov 10, 2022

Thanks for the review!

@joshlf joshlf merged commit 8201cbf into main Nov 10, 2022
@joshlf joshlf deleted the deref-unalign branch November 10, 2022 00:46
@joshlf joshlf mentioned this pull request Nov 10, 2022
3 tasks
joshlf added a commit that referenced this pull request Aug 3, 2023
Provide methods and trait implementations to generate `&T` and `&mut T`
from `&Unalign<T>` and `&mut Unalign<T>` respectively. If `T:
Unaligned`, then these are infallible. Otherwise, a runtime check must
be performed to ensure that the `Unalign<T>` satisfies `T`'s alignment
requirement.

Since dereferencing is now supported, we can also implement various
traits using `Deref` and `DerefMut` impls.
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 this pull request may close these issues.

2 participants