use hex::FromHexError;
use std::str::FromStr;
#[derive(
derive_more::Debug,
Clone,
derive_more::AsRef,
derive_more::AsMut,
derive_more::Deref,
derive_more::DerefMut,
derive_more::Into,
derive_more::From,
derive_more::Display,
)]
#[as_ref(forward)]
#[as_mut(forward)]
#[deref(forward)]
#[deref_mut(forward)]
#[display("0x{}", hex::encode(self))]
#[debug("0x{}", hex::encode(self))]
pub struct HexBytes(Vec<u8>);
impl HexBytes {
pub fn as_slice(&self) -> &[u8] {
self
}
pub fn as_slice_mut(&mut self) -> &mut [u8] {
self
}
pub fn into_vec(self) -> Vec<u8> {
self.into()
}
}
impl FromStr for HexBytes {
type Err = FromHexError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
hex::decode(s.trim_start_matches("0x")).map(Self)
}
}