1use std::{fmt, mem::transmute};
2
3use bytemuck::{Pod, Zeroable};
4use solana_program::keccak::{Hash as KeccakHash, HASH_BYTES};
5
6use crate::impl_to_bytes;
7
8#[repr(C)]
10#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
11pub struct Hash(pub [u8; HASH_BYTES]);
12
13impl From<KeccakHash> for Hash {
14 #[inline(always)]
15 fn from(value: KeccakHash) -> Self {
16 unsafe { transmute(value) }
17 }
18}
19
20impl From<Hash> for KeccakHash {
21 #[inline(always)]
22 fn from(value: Hash) -> Self {
23 unsafe { transmute(value) }
24 }
25}
26
27impl fmt::Display for Hash {
28 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29 write!(f, "{}", bs58::encode(self.0).into_string())
30 }
31}
32
33impl_to_bytes!(Hash);