ibc_types_domain_type/
lib.rs1#![no_std]
3#![cfg_attr(docsrs, feature(doc_auto_cfg))]
5
6extern crate alloc;
7#[cfg(any(test, feature = "std"))]
8extern crate std;
9
10mod prelude;
11use prelude::*;
12
13pub trait DomainType
15where
16 Self: Clone + Sized + TryFrom<Self::Proto>,
17 Self::Proto: prost::Message + prost::Name + Default + From<Self> + Send + Sync + 'static,
18 <Self as TryFrom<Self::Proto>>::Error: Into<anyhow::Error> + Send + Sync + 'static,
19{
20 type Proto;
21
22 fn encode_to_vec(&self) -> Vec<u8> {
24 use prost::Message;
25 self.to_proto().encode_to_vec()
26 }
27
28 fn to_proto(&self) -> Self::Proto {
33 Self::Proto::from(self.clone())
34 }
35
36 fn decode<B: bytes::Buf>(buf: B) -> Result<Self, anyhow::Error> {
38 <Self::Proto as prost::Message>::decode(buf)
39 .map_err(anyhow::Error::msg)?
40 .try_into()
41 .map_err(Into::into)
42 }
43}