Skip to content

Commit dd95b98

Browse files
committed
use a repr(C) struct with a [T; 0] as first field for alignment
This is a bit cleaner than using a union For discussion about see: kazcw/alignas#1 (comment)
1 parent 4551f95 commit dd95b98

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ struct HeaderVecHeader<H> {
5151
len: usize,
5252
}
5353

54-
// This union will be properly aligned and sized to store headers followed by T's.
55-
union AlignedHeader<H, T> {
56-
_header: ManuallyDrop<HeaderVecHeader<H>>,
57-
_data: ManuallyDrop<[T; 0]>,
54+
// This struct will be properly aligned and sized to store headers followed by T's.
55+
#[repr(C)]
56+
struct AlignedHeader<H, T> {
57+
align: [T; 0],
58+
header: HeaderVecHeader<H>,
5859
}
5960

6061
/// A vector with a header of your choosing behind a thin pointer

0 commit comments

Comments
 (0)