0x34, 0x56, 0x78]) }; let val = if cfg!(target_endianess = "little") { raw.swap_bytes() } else { raw }; assert_eq!(val, 0x12345678); let raw = unsafe { transmute::<[u8; 4], u32>([0x12, 0x34, 0x56, 0x78]) }; let val = u32::from_be(raw); assert_eq!(val, 0x12345678);