cosmwasm_std/
import_helpers.rs

1/// Returns the four most significant bytes
2#[allow(dead_code)] // only used in Wasm builds
3#[inline]
4pub fn from_high_half(data: u64) -> u32 {
5    (data >> 32).try_into().unwrap()
6}
7
8/// Returns the four least significant bytes
9#[allow(dead_code)] // only used in Wasm builds
10#[inline]
11pub fn from_low_half(data: u64) -> u32 {
12    (data & 0xFFFFFFFF).try_into().unwrap()
13}
14
15#[cfg(test)]
16mod tests {
17    use super::*;
18
19    #[test]
20    fn from_high_half_works() {
21        assert_eq!(from_high_half(0), 0);
22        assert_eq!(from_high_half(0x1122334455667788), 0x11223344);
23    }
24
25    #[test]
26    fn from_low_haf_works() {
27        assert_eq!(from_low_half(0), 0);
28        assert_eq!(from_low_half(0x1122334455667788), 0x55667788);
29    }
30}