1use serde::{de::DeserializeOwned, Serialize};
7
8pub trait FromBcsBytes: Sized {
10 fn from_bcs_bytes(bytes: &[u8]) -> Result<Self, bcs::Error>;
12}
13
14impl<T> FromBcsBytes for T
15where
16 T: DeserializeOwned,
17{
18 fn from_bcs_bytes(bytes: &[u8]) -> Result<Self, bcs::Error> {
19 bcs::from_bytes(bytes)
20 }
21}
22
23pub trait ToBcsBytes {
25 fn to_bcs_bytes(&self) -> Result<Vec<u8>, bcs::Error>;
27}
28
29impl<T> ToBcsBytes for T
30where
31 T: Serialize,
32{
33 fn to_bcs_bytes(&self) -> Result<Vec<u8>, bcs::Error> {
34 bcs::to_bytes(self)
35 }
36}