glam/
align16.rs

1#[derive(Clone, Copy, Default, PartialEq, PartialOrd)]
2#[repr(C, align(16))]
3pub(crate) struct Align16<T>(pub T);
4
5impl<T> Align16<T> {
6    #[allow(dead_code)]
7    pub fn as_ptr(&self) -> *const T {
8        &self.0
9    }
10
11    #[allow(dead_code)]
12    pub fn as_mut_ptr(&mut self) -> *mut T {
13        &mut self.0
14    }
15}
16
17#[test]
18fn test_align16() {
19    use core::{mem, ptr};
20    let mut a = Align16::<f32>(1.0);
21    assert_eq!(mem::align_of_val(&a), 16);
22    unsafe {
23        assert_eq!(ptr::read(a.as_ptr()).to_bits(), f32::to_bits(1.0));
24        ptr::write(a.as_mut_ptr(), -1.0);
25    }
26    assert_eq!(a.0.to_bits(), f32::to_bits(-1.0));
27}