extern crate pod; use pod::Pod; #[repr(C)] struct Unaligned { _pad0: u8, value: [u8; 2], _pad1: u8, _align: u32, } #[test] fn test_map() { let mut un = Unaligned { _pad0: 0, value: [1, 1], _pad1: 0, _align: 0, }; let un = &mut un.value; assert!(0u16.map::().is_none()); assert!(0u16.map_mut::().is_none()); assert!(0u16.map_copy::().is_none()); assert!(0u16.try_map::().unwrap() == &0); assert!(0u16.try_map_mut::().unwrap() == &mut 0); assert!(Pod::map_box::(Box::new(0u16)).is_err()); assert!(0u16.map::().is_none()); assert!(0u16.map_mut::().is_none()); assert!(0u16.map_copy::().is_none()); assert!(0u16.try_map::().is_none()); assert!(0u16.try_map_mut::().is_none()); assert!(Pod::map_box::(Box::new(0u16)).is_err()); assert!(0xffu16.map::().unwrap() == &0xffi16); assert!(0xffu16.map_mut::().unwrap() == &mut 0xffi16); assert!(0xffu16.map_copy::().unwrap() == 0xffi16); assert!(0xffu16.try_map::().unwrap() == &0xff); assert!(0xffu16.try_map_mut::().unwrap() == &mut 0xff); assert!(*Pod::map_box::(Box::new(0xffu16)).unwrap() == 0xff); assert!(un.map::().is_none()); assert!(un.map_mut::().is_none()); assert!(un.map_copy::().unwrap() == 0x0101i16); assert!(un.try_map::().is_none()); assert!(un.try_map_mut::().is_none()); }