1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
pub type Error = Box<dyn std::error::Error>;
use pallas_codec::minicbor::{decode, to_vec, Decode, Encode};
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: Encode<()> + Decode<'a, ()> + Sized,
{
fn encode_fragment(&self) -> Result<Vec<u8>, Error> {
to_vec(self).map_err(|e| e.into())
}
fn decode_fragment(bytes: &'a [u8]) -> Result<Self, Error> {
decode(bytes).map_err(|e| e.into())
}
}
#[cfg(feature = "json")]
pub trait ToCanonicalJson {
fn to_json(&self) -> serde_json::Value;
}
pub trait ToHash<const BYTES: usize> {
fn to_hash(&self) -> pallas_crypto::hash::Hash<BYTES>;
}