macro_rules! impl_consensus_encoding {
( $thing:ident, $($field:ident),+ ) => (
#[sealed::sealed]
impl $crate::consensus::encode::Encodable for $thing {
#[inline]
fn consensus_encode<W: ::std::io::Write + ?Sized>(
&self,
w: &mut W
) -> Result<usize, ::std::io::Error> {
let mut len = 0;
$( len += self.$field.consensus_encode(w)?; )+
Ok(len)
}
}
impl $crate::consensus::encode::Decodable for $thing {
#[inline]
fn consensus_decode<R: ::std::io::Read + ?Sized>(
r: &mut R
) -> Result<$thing, $crate::consensus::encode::Error> {
Ok($thing {
$( $field: crate::consensus::encode::Decodable::consensus_decode(r)?, )+
})
}
}
);
}
macro_rules! impl_hex_display {
( $data:ident, $field:ident ) => {
impl fmt::Debug for $data {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", hex::encode(&self.$field[..]))
}
}
impl fmt::Display for $data {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", hex::encode(&self.$field[..]))
}
}
};
}