I need to align a struct to a 16 byte boundary in Rust. It seems possible to give hints about alignment through the repr
attribute, but it doesn't support this exact use case.
A functional test of what I'm trying to achieve is a type Foo
such that
assert_eq!(mem::align_of::<Foo>(), 16);
or alternatively, a struct Bar
with a field baz
such that
println!("{:p}", Bar::new().baz);
always prints a number divisible by 16.
Is this currently possible in Rust? Are there any work-arounds?
allocate
does have an alignment argument. – Verisimilar