multiversx_sc_codec/multi/multi_value_length.rs
1use crate::{TopDecode, TopEncode};
2
3/// Indicates that a multi-value has a countable number of single items contained.
4///
5/// This applies to single items as well, which have a multi value length of 1.
6pub trait MultiValueLength {
7 /// The number of single items contained a multi-value.
8 fn multi_value_len(&self) -> usize;
9}
10
11/// Indicates that a multi-value has a fixed (constant) number of single items contained.
12///
13/// This applies to:
14/// - single items
15/// - multi-value tuples
16pub trait MultiValueConstLength {
17 /// The fixed (constant) number of single items contained a multi-value.
18 ///
19 /// Its value is:
20 /// - for single items: 1,
21 /// - for multi-value tuples: the sum of the fixed lengths of their items, if applicable.
22 const MULTI_VALUE_CONST_LEN: usize;
23}
24
25impl<T> MultiValueLength for T
26where
27 T: TopEncode + TopDecode,
28{
29 #[inline]
30 fn multi_value_len(&self) -> usize {
31 1
32 }
33}
34
35impl<T> MultiValueConstLength for T
36where
37 T: TopEncode + TopDecode,
38{
39 const MULTI_VALUE_CONST_LEN: usize = 1;
40}