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

struct AlignedVec: Make generic over alignment #764

Merged
merged 3 commits into from
Feb 27, 2024

Conversation

kkysen
Copy link
Collaborator

@kkysen kkysen commented Feb 27, 2024

This makes AlignedVec generic over alignments by using a marker trait AlignedByteChunk impled for types with the same alignment and size (e.x. Align64<[u8; 64]>. Since #[repr(align(N))] is not a const generic, const generics couldn't be used for this, but this works nicely. We check that mem::size_of::<C>() == mem::align_of::<C>() in AlignedVec's constructors to ensure AlignedByteChunk is impled on valid types. Thus, I also ensured that the AlignedVecs were actually constructed, not transmuted through unsafe { mem::zeroed() }.

@kkysen kkysen changed the title AlignedVec: Make generic over alignment struct AlignedVec: Make generic over alignment Feb 27, 2024
@kkysen kkysen merged commit 08f6b7c into main Feb 27, 2024
34 checks passed
@kkysen kkysen deleted the kkysen/struct-AlignedVec-const-generic branch February 27, 2024 18:51
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