-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Remove the need to specify <T>
for parts in construct_runtime!
(like Event<T>
)
#8743
Comments
Hey, is anyone still working on this? Due to the inactivity this issue has been automatically marked as stale. It will be closed if no further activity occurs. Thank you for your contributions. |
still relevant |
What happens if there is data in an |
no this isn't what I meant, event type can still be generic, but the configuration of the part doesn't require to give this information. This can be achieve by using trait implemented on the pallet struct:
(maybe the trait and construct_runtime will always access the Event from the pallet struct throught the trait. |
Solving this issue is actually a prerequisite to #8084, because an "import all declared pallet parts" syntax by definition does not include a generic for the pallet parts that require it. |
actually when pallet declare their parts they can also declare their part with the correct generic. But I agree it can make code simpler. |
Hmm ok, so the issue is when we try to implement impl<T: Config> PalletEvent for Pallet<T> {
type Event = path::to::pallet::Event<T>;
} ... because the |
but the event type is declared inside the |
Not when we're calling |
Huh, so the inability to store local state and have it reused between macro invocations is actually a known issue since 2017: rust-lang/rust#44034 |
Oh ok, I guess what I can do instead is declare the trait in the pallet, and implement the trait there. Then |
yes this is the plan |
This PR #9681 doe the automatic declaration of pallet parts. Maybe this issue can be considered fixed then |
personally I would close this issue, with the new syntax nobody should declare the part manually, instead they only whitelist or blacklist parts. Feel free to re-open if you disagree |
My current PR can only support non-generic |
Instead of fetching the type from the macro we can fetch the type from the
Pallet
struct placeholder.We introduce a trait
trait PalletEvent { type Event }
,we implement it for the pallet placeholder.
and then we use
<Pallet<Runtime> as PalletEvent>::Event
when building the aggregated runtime event.Thus there is no longer need for specify the generics of the
Event
type.Same for
Origin
andConfig
.This main advantage of it is in to not have these difficult compilation error when the generics are wrongly specified.
The text was updated successfully, but these errors were encountered: