1 #![feature(const_int_conversion)]
3 const REVERSE: u32 = 0x12345678_u32.reverse_bits();
4 const FROM_BE_BYTES: i32 = i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]);
5 const FROM_LE_BYTES: i32 = i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]);
6 const FROM_NE_BYTES: i32 = i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0]));
7 const TO_BE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_be_bytes();
8 const TO_LE_BYTES: [u8; 4] = 0x12_34_56_78_i32.to_le_bytes();
9 const TO_NE_BYTES: [u8; 4] = i32::min_value().to_be().to_ne_bytes();
11 fn ident<T>(ident: T) -> T {
16 assert_eq!(REVERSE, ident(0x1e6a2c48));
17 assert_eq!(FROM_BE_BYTES, ident(0x12_34_56_78));
18 assert_eq!(FROM_LE_BYTES, ident(0x78_56_34_12));
19 assert_eq!(FROM_NE_BYTES, ident(i32::min_value()));
20 assert_eq!(TO_BE_BYTES, ident([0x12, 0x34, 0x56, 0x78]));
21 assert_eq!(TO_LE_BYTES, ident([0x78, 0x56, 0x34, 0x12]));
22 assert_eq!(TO_NE_BYTES, ident([0x80, 0, 0, 0]));