mod hex;
pub mod serde;
pub use hex::{decode_hex, encode_hex};
use crate::{FromHexError, ToHex};
pub trait ToHexCore {
type Bytes;
type Buffer;
fn create_buffer(len: usize) -> Self::Buffer;
fn buffer_as_bytes(buffer: &mut Self::Buffer) -> &mut [u8];
fn to_binary_bytes(&self) -> Self::Bytes;
fn as_binary_bytes<'a>(&'a self, bytes: &'a Self::Bytes) -> &'a [u8];
}
pub trait FromHexCore: Sized {
type Bytes;
fn create_bytes(len: Option<usize>) -> Self::Bytes;
fn bytes_as_mut(bytes: &mut Self::Bytes) -> &mut [u8];
fn from_binary_bytes(bytes: Self::Bytes) -> Result<Self, FromHexError>;
}
pub fn with_hex_str<T, U>(value: &T, f: impl FnOnce(&str) -> U) -> U
where
T: ?Sized + ToHex,
{
let bytes = value.to_binary_bytes();
let bytes = value.as_binary_bytes(&bytes);
let mut buffer = T::create_buffer(bytes.len() * 2);
let buffer = T::buffer_as_bytes(&mut buffer);
f(encode_hex(bytes, buffer))
}