1

I'm a newcomer to Rust and have been working with the Substrate-Parachain-Template. So far, I've managed to get everything to compile and run without issue, which is a good start.

However, I've come across a part of the code that I'm struggling to understand, specifically the RuntimeEvent type resolution. Here's a snippet of the code in question:

impl pallet_nicks::Config for Runtime {
    .....
    // The ubiquitous event type.
    type Event = RuntimeEvent;
}

I'm confused about the RuntimeEvent type because there isn't an explicit import statement for it, and yet it doesn't seem to be causing any issues. It feels like magic, but I know that's not how programming works.

Could anyone kindly explain how Rust is resolving this type? I've checked the documentation but I couldn't find a clear explanation on this matter.

Any insight would be greatly appreciated. Thank you in advance!

Best Regards, AnonDao

1 Answer 1

1

In Rust, the associated types are types that are associated with a trait and defined within the trait itself or its implementing type. They allow traits to specify additional types that are relevant to their functionality.

In the context of the pallet_nicks::Config trait, the type Event is an associated type that represents the event type for that configuration. By declaring type Runtime = Runtime, it means that the type Runtime is being used as a self-reference or a way to refer to the overall runtime configuration itself. It allows the code within the pallet to work with and refer to the runtime configuration without needing to specify the exact type.

You can see read the docs here for understanding the runtime configurations and the you can check the impl of construct_runtime

1
  • So, when you see the line type RuntimeEvent = RuntimeEvent; in the pallet_nicks::Config implementation for Runtime, is it correct to say that the associated RuntimeEvent type is implicitly referencing the RuntimeEvent that's generated by construct_runtime!?
    – AnonDao
    Jul 7 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.