fuel_core_storage/codec/
raw.rsuse crate::codec::{
Decode,
Encode,
};
#[cfg(feature = "std")]
use std::borrow::Cow;
#[cfg(not(feature = "std"))]
use alloc::borrow::Cow;
pub struct Raw;
impl<T> Encode<T> for Raw
where
T: ?Sized + AsRef<[u8]>,
{
type Encoder<'a> = Cow<'a, [u8]> where T: 'a;
fn encode(t: &T) -> Self::Encoder<'_> {
Cow::Borrowed(t.as_ref())
}
}
impl<T> Decode<T> for Raw
where
for<'a> T: TryFrom<&'a [u8]>,
{
fn decode(bytes: &[u8]) -> anyhow::Result<T> {
T::try_from(bytes).map_err(|_| anyhow::anyhow!("Unable to decode bytes"))
}
}