use std::collections::HashMap;
use std::ffi::CString;
pub trait AsInner {
type Type;
fn inner(&self) -> &Self::Type;
}
pub trait IntoInner {
type Type;
fn into_inner(self) -> Self::Type;
}
pub trait AsBytes {
fn as_bytes(&self) -> &[u8];
}
macro_rules! strings_as_bytes {
($implementor:ty) => {
impl AsBytes for $implementor {
fn as_bytes(&self) -> &[u8] {
<Self>::as_bytes(&self)
}
}
impl AsBytes for &$implementor {
fn as_bytes(&self) -> &[u8] {
<$implementor>::as_bytes(&self)
}
}
};
}
macro_rules! vecs_as_bytes {
($implementor:ty) => {
impl AsBytes for $implementor {
fn as_bytes(&self) -> &[u8] {
self.as_slice()
}
}
impl AsBytes for &$implementor {
fn as_bytes(&self) -> &[u8] {
self.as_slice()
}
}
};
}
vecs_as_bytes!(Vec<u8>);
strings_as_bytes!(String);
strings_as_bytes!(str);
strings_as_bytes!(CString);
impl<BH> IntoInner for HashMap<String, Vec<u8>, BH>
where
BH: std::hash::BuildHasher,
{
type Type = Self;
fn into_inner(self) -> Self::Type {
self
}
}