use core::fmt;
use core::fmt::Display;
use core::fmt::Formatter;
use std::ops::Deref;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct HashRef<'h>(&'h [u8]);
impl<'h> HashRef<'h> {
pub fn new(bytes: &[u8]) -> HashRef<'_> {
HashRef(bytes)
}
pub fn as_bytes(&self) -> &[u8] {
self.0
}
pub fn as_hex(&self) -> String {
hex::encode(self.0)
}
}
impl<'h> Deref for HashRef<'h> {
type Target = [u8];
fn deref(&self) -> &[u8] {
self.as_bytes()
}
}
impl<'h> Display for HashRef<'h> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_hex())
}
}