use core::convert::TryFrom;
#[derive(Debug)]
pub struct TranscodingError;
impl core::error::Error for TranscodingError {}
impl core::fmt::Display for TranscodingError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Transcoding error")
}
}
impl From<crate::FFIError> for TranscodingError {
fn from(_: crate::FFIError) -> Self {
TranscodingError {}
}
}
impl From<generic_array::LengthError> for TranscodingError {
fn from(_: generic_array::LengthError) -> Self {
TranscodingError {}
}
}
pub trait AsBytes: AsRef<[u8]> {
#[inline]
fn as_bytes(&self) -> &[u8] {
self.as_ref()
}
}
impl<T> AsBytes for T where T: AsRef<[u8]> {}
pub trait FromBytes: Sized {
type Error;
fn from_bytes(input: &[u8]) -> Result<Self, Self::Error>;
}
impl<T, E> FromBytes for T
where
for<'a> T: TryFrom<&'a [u8], Error = E>,
{
type Error = E;
#[inline]
fn from_bytes(input: &[u8]) -> Result<Self, Self::Error> {
<T as TryFrom<&[u8]>>::try_from(input)
}
}