• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #[derive(Clone, Copy, Default, PartialEq, PartialOrd)]
2 #[repr(C, align(16))]
3 pub(crate) struct Align16<T>(pub T);
4 
5 impl<T> Align16<T> {
6     #[allow(dead_code)]
as_ptr(&self) -> *const T7     pub fn as_ptr(&self) -> *const T {
8         &self.0
9     }
10 
11     #[allow(dead_code)]
as_mut_ptr(&mut self) -> *mut T12     pub fn as_mut_ptr(&mut self) -> *mut T {
13         &mut self.0
14     }
15 }
16 
17 #[test]
test_align16()18 fn 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 }
28