chore: Merge Byron / Alonzo into single crate (#43)

This commit is contained in:
Santiago Carmuega 2022-02-09 07:19:17 -03:00 committed by GitHub
parent c5dff33113
commit 21a3077883
61 changed files with 120 additions and 335 deletions

View file

@ -0,0 +1,22 @@
pub type Error = Box<dyn std::error::Error>;
pub trait Fragment<'a>
where
Self: Sized,
{
fn encode_fragment(&self) -> Result<Vec<u8>, Error>;
fn decode_fragment(bytes: &'a [u8]) -> Result<Self, Error>;
}
impl<'a, T> Fragment<'a> for T
where
T: minicbor::Encode + minicbor::Decode<'a> + Sized,
{
fn encode_fragment(&self) -> Result<Vec<u8>, Error> {
minicbor::to_vec(self).map_err(|e| e.into())
}
fn decode_fragment(bytes: &'a [u8]) -> Result<Self, Error> {
minicbor::decode(bytes).map_err(|e| e.into())
}
}