use base64::Engine;
pub trait Encoder {
fn encode<Bytes>(&self, data: Bytes) -> String
where
Bytes: AsRef<[u8]>;
}
#[derive(Debug, Copy, Clone)]
pub struct HexEncoder;
impl Encoder for HexEncoder {
fn encode<Bytes>(&self, data: Bytes) -> String
where
Bytes: AsRef<[u8]>,
{
hex::encode(data)
}
}
#[derive(Debug, Copy, Clone)]
pub struct Base64Encoder;
impl Encoder for Base64Encoder {
fn encode<Bytes>(&self, data: Bytes) -> String
where
Bytes: AsRef<[u8]>,
{
base64::engine::general_purpose::STANDARD.encode(data)
}
}