#[derive(MaxEncodedLen)] (#8737)

* impl #[derive(MaxEncodedLen)] for structs

* impl #[derive(MaxEncodedLen)] for enums, unions

* break long comments onto multiple lines

* add doc for public item

* add examples to macro documentation

* move MaxEncodedLen macro docs, un-ignore doc-tests
This commit is contained in:
Peter Goodspeed-Niklaus
2021-05-07 10:18:09 +02:00
committed by GitHub
parent e1caa2979f
commit 17a1997d18
13 changed files with 442 additions and 0 deletions
+28
View File
@@ -82,4 +82,32 @@ mod voting;
pub use voting::{CurrencyToVote, SaturatingCurrencyToVote, U128CurrencyToVote};
mod max_encoded_len;
// This looks like an overlapping import/export, but it isn't:
// macros and traits live in distinct namespaces.
pub use max_encoded_len::MaxEncodedLen;
/// Derive [`MaxEncodedLen`][max_encoded_len::MaxEncodedLen].
///
/// # Examples
///
/// ```
/// # use codec::Encode;
/// # use frame_support::traits::MaxEncodedLen;
/// #[derive(Encode, MaxEncodedLen)]
/// struct TupleStruct(u8, u32);
///
/// assert_eq!(TupleStruct::max_encoded_len(), u8::max_encoded_len() + u32::max_encoded_len());
/// ```
///
/// ```
/// # use codec::Encode;
/// # use frame_support::traits::MaxEncodedLen;
/// #[derive(Encode, MaxEncodedLen)]
/// enum GenericEnum<T> {
/// A,
/// B(T),
/// }
///
/// assert_eq!(GenericEnum::<u8>::max_encoded_len(), u8::max_encoded_len() + u8::max_encoded_len());
/// assert_eq!(GenericEnum::<u128>::max_encoded_len(), u8::max_encoded_len() + u128::max_encoded_len());
/// ```
pub use frame_support_procedural::MaxEncodedLen;