Skip to main content

solana_ledger/shred/
common.rs

1macro_rules! dispatch {
2    ($vis:vis fn $name:ident(&self $(, $arg:ident : $ty:ty)?) $(-> $out:ty)?) => {
3        #[inline]
4        $vis fn $name(&self $(, $arg:$ty)?) $(-> $out)? {
5            match self {
6                Self::Merkle(shred) => shred.$name($($arg, )?),
7            }
8        }
9    };
10    ($vis:vis fn $name:ident(self $(, $arg:ident : $ty:ty)?) $(-> $out:ty)?) => {
11        #[inline]
12        $vis fn $name(self $(, $arg:$ty)?) $(-> $out)? {
13            match self {
14                Self::Merkle(shred) => shred.$name($($arg, )?),
15            }
16        }
17    };
18    ($vis:vis fn $name:ident(&mut self $(, $arg:ident : $ty:ty)?) $(-> $out:ty)?) => {
19        #[inline]
20        $vis fn $name(&mut self $(, $arg:$ty)?) $(-> $out)? {
21            match self {
22                Self::Merkle(shred) => shred.$name($($arg, )?),
23            }
24        }
25    }
26}
27
28macro_rules! impl_shred_common {
29    () => {
30        #[inline]
31        fn common_header(&self) -> &ShredCommonHeader {
32            &self.common_header
33        }
34
35        #[inline]
36        fn payload(&self) -> &Payload {
37            &self.payload
38        }
39
40        #[inline]
41        fn into_payload(self) -> Payload {
42            self.payload
43        }
44
45        #[inline]
46        fn set_signature(&mut self, signature: Signature) {
47            self.payload.as_mut()[..SIZE_OF_SIGNATURE].copy_from_slice(signature.as_ref());
48            self.common_header.signature = signature;
49        }
50    };
51}
52
53pub(super) use {dispatch, impl_shred_common};