Convert impl_key_prefix_for to proc macro (#8844)

* Convert impl_key_prefix_for to proc macro

* Reduce the number of let bindings

* Remove parsing of inputs for impl_key_prefix_for_tuples

* Replace unwrap with expect

* Remove unnecessary array of idents

* Use numeric identifiers

* Simplify ident generation

* Fix whitespacing

* Add documentation for impl_key_prefix_for_tuple proc macro

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>

Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Keith Yeung
2021-05-26 16:22:35 -07:00
committed by GitHub
parent c110425251
commit 053be60b82
3 changed files with 105 additions and 733 deletions
@@ -29,6 +29,7 @@ mod clone_no_bound;
mod partial_eq_no_bound;
mod default_no_bound;
mod max_encoded_len;
mod key_prefix;
pub(crate) use storage::INHERENT_INSTANCE_NAME;
use proc_macro::TokenStream;
@@ -451,3 +452,10 @@ pub(crate) const NUMBER_OF_INSTANCE: u8 = 16;
pub fn derive_max_encoded_len(input: TokenStream) -> TokenStream {
max_encoded_len::derive_max_encoded_len(input)
}
/// This macro is meant to be used by frame-support only.
/// It implements the trait `HasKeyPrefix` and `HasReversibleKeyPrefix` for tuple of `Key`.
#[proc_macro]
pub fn impl_key_prefix_for_tuples(input: TokenStream) -> TokenStream {
key_prefix::impl_key_prefix_for_tuples(input).unwrap_or_else(syn::Error::into_compile_error).into()
}