Elain
Set the minimum alignments of types using const generics, rather
than #[repr(align(N))]
.
Basic Use
The type Align<N>
is a zero-sized-type with alignment
equal to N
:
use Align;
use ;
assert_eq!;
assert_eq!;
assert_eq!;
const FOO_ALIGN: usize = 8;
let foo: Foo = Foo ;
assert_eq!;
Valid alignments are powers of two less-than-or-equal to 228.
Supplying an invalid alignment to [Align
] is a type error:
use Align;
; // Compile Error
Generic Use
Because only some integers are valid alignments, supplying the alignment of a type generically requires some extra work:
use Align;
To resolve this error, add a where
bound like so, using the
[Alignment
] trait to check that Align<N>
is valid.
use ;
use align_of;
assert_eq!;
assert_eq!;
assert_eq!;