mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
pallet macro: easier syntax for #[pallet::pallet] with struct Pallet<T>(_) (#8091)
This commit is contained in:
committed by
GitHub
parent
2d31af3eb6
commit
e78d139676
@@ -26,7 +26,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
// The pallet's runtime storage items.
|
||||
// https://substrate.dev/docs/en/knowledgebase/runtime/storage
|
||||
|
||||
@@ -143,7 +143,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
/// The module configuration trait.
|
||||
|
||||
@@ -22,6 +22,7 @@ use crate::pallet::Def;
|
||||
/// * Implement OnGenesis on Pallet
|
||||
/// * Implement ModuleErrorMetadata on Pallet
|
||||
/// * declare Module type alias for construct_runtime
|
||||
/// * replace the first field type of `struct Pallet` with `PhantomData` if it is `_`
|
||||
pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
let frame_support = &def.frame_support;
|
||||
let frame_system = &def.frame_system;
|
||||
@@ -41,6 +42,15 @@ pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
}
|
||||
};
|
||||
|
||||
// If the first field type is `_` then we replace with `PhantomData`
|
||||
if let Some(field) = pallet_item.fields.iter_mut().next() {
|
||||
if field.ty == syn::parse_quote!(_) {
|
||||
field.ty = syn::parse_quote!(
|
||||
#frame_support::sp_std::marker::PhantomData<(#type_use_gen)>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pallet_item.attrs.push(syn::parse_quote!(
|
||||
#[derive(
|
||||
#frame_support::CloneNoBound,
|
||||
|
||||
@@ -1141,7 +1141,7 @@ pub mod pallet_prelude {
|
||||
/// Item must be defined as followed:
|
||||
/// ```ignore
|
||||
/// #[pallet::pallet]
|
||||
/// pub struct Pallet<T>(PhantomData<T>);
|
||||
/// pub struct Pallet<T>(_);
|
||||
/// ```
|
||||
/// I.e. a regular struct definition named `Pallet`, with generic T and no where clause.
|
||||
///
|
||||
@@ -1150,7 +1150,7 @@ pub mod pallet_prelude {
|
||||
/// ```ignore
|
||||
/// #[pallet::pallet]
|
||||
/// #[pallet::generate_store(pub(super) trait Store)]
|
||||
/// pub struct Pallet<T>(PhantomData<T>);
|
||||
/// pub struct Pallet<T>(_);
|
||||
/// ```
|
||||
/// More precisely the store trait contains an associated type for each storage. It is implemented
|
||||
/// for `Pallet` allowing to access the storage from pallet struct.
|
||||
@@ -1169,6 +1169,7 @@ pub mod pallet_prelude {
|
||||
/// frame_support::RuntimeDebugNoBound,
|
||||
/// )]
|
||||
/// ```
|
||||
/// and replace the type `_` by `PhantomData<T>`.
|
||||
///
|
||||
/// It implements on pallet:
|
||||
/// * [`traits::GetPalletVersion`]
|
||||
@@ -1602,7 +1603,7 @@ pub mod pallet_prelude {
|
||||
/// // Define the pallet struct placeholder, various pallet function are implemented on it.
|
||||
/// #[pallet::pallet]
|
||||
/// #[pallet::generate_store(pub(super) trait Store)]
|
||||
/// pub struct Pallet<T>(PhantomData<T>);
|
||||
/// pub struct Pallet<T>(_);
|
||||
///
|
||||
/// // Implement the pallet hooks.
|
||||
/// #[pallet::hooks]
|
||||
@@ -1920,7 +1921,7 @@ pub mod pallet_prelude {
|
||||
/// #[pallet::generate_store($visibility_of_trait_store trait Store)]
|
||||
/// // NOTE: if the visibility of trait store is private but you want to make it available
|
||||
/// // in super, then use `pub(super)` or `pub(crate)` to make it available in crate.
|
||||
/// pub struct Pallet<T>(PhantomData<T>);
|
||||
/// pub struct Pallet<T>(_);
|
||||
/// // pub struct Pallet<T, I = ()>(PhantomData<T>); // for instantiable pallet
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@@ -100,7 +100,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(crate) trait Store)]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
|
||||
@@ -290,7 +290,7 @@ pub mod pallet2 {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(crate) trait Store)]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
|
||||
|
||||
@@ -106,7 +106,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<T::BlockNumber> for Pallet<T> {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::{Hooks, PhantomData};
|
||||
use frame_support::pallet_prelude::Hooks;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks for Pallet<T> {}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::{Hooks, PhantomData};
|
||||
use frame_support::pallet_prelude::Hooks;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#[frame_support::pallet]
|
||||
mod pallet {
|
||||
use frame_support::pallet_prelude::{Hooks, PhantomData};
|
||||
use frame_support::pallet_prelude::Hooks;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
#[pallet::config]
|
||||
@@ -9,7 +9,7 @@ mod pallet {
|
||||
{}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
|
||||
|
||||
@@ -7,7 +7,7 @@ mod pallet {
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
@@ -7,7 +7,7 @@ mod pallet {
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
|
||||
|
||||
@@ -86,7 +86,7 @@ mod pallet3 {
|
||||
}
|
||||
|
||||
#[pallet::pallet]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
|
||||
@@ -257,7 +257,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub (super) trait Store)]
|
||||
pub struct Pallet<T>(PhantomData<T>);
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
|
||||
Reference in New Issue
Block a user