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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…