radix_transactions/model/preparation/
summary.rs

1use crate::internal_prelude::*;
2
3/// This is created as part of the preparation of a transaction, during decoding.
4#[derive(Debug, Clone, Eq, PartialEq)]
5pub struct Summary {
6    /// This is an approximation of the encoded length of the underlying items contained within the item,
7    /// which needs to be **deterministic** from the information in the hash.
8    /// Not necessarily the _actual_ length of the payload.
9    pub effective_length: usize,
10    /// The total number of bytes which were hashed.
11    pub total_bytes_hashed: usize,
12    /// The hash by which this payload is identified.
13    /// This might be a hash of the payload itself, or of a composite hash of some concatenation of other hashes/values.
14    pub hash: Hash,
15}
16
17pub trait HasSummary {
18    fn get_summary(&self) -> &Summary;
19    fn summary_mut(&mut self) -> &mut Summary;
20}
21
22macro_rules! impl_has_summary {
23    (
24        $(< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? $( = $deflt:tt)? ),+ >)?
25        $prepared:ident
26        $(< $($rt:tt),+ >)?
27    ) => {
28        #[allow(deprecated)]
29        impl
30            $(< $( $lt $( : $clt $(+ $dlt )* )? $( = $deflt)? ),+ >)?
31            HasSummary for $prepared
32            $(< $( $rt ),+ >)?
33        {
34            fn get_summary(&self) -> &Summary {
35                &self.summary
36            }
37
38            fn summary_mut(&mut self) -> &mut Summary {
39                &mut self.summary
40            }
41        }
42    };
43}
44
45pub(crate) use impl_has_summary;