Skip to content

Commit

Permalink
Finish documenting #[pallet::xxx] macros (#2638)
Browse files Browse the repository at this point in the history
Closes paritytech/polkadot-sdk-docs#35

- Moves pallet proc macro docs to `frame_support`
- Adds missing docs
- Revise revise existing docs, adding compiling doctests where
appropriate

---------

Co-authored-by: command-bot <>
Co-authored-by: Kian Paimani <[email protected]>
  • Loading branch information
liamaharon and kianenigma authored Mar 3, 2024
1 parent cdc8d19 commit b0741d4
Show file tree
Hide file tree
Showing 5 changed files with 1,127 additions and 1,987 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 12 additions & 8 deletions docs/sdk/src/guides/your_first_pallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,16 @@
// of event is probably not the best.
//!
//! With the explanation out of the way, let's see how these components can be added. Both follow a
//! fairly familiar syntax: normal Rust enums, with an extra `#[frame::event/error]` attribute
//! attached.
//! fairly familiar syntax: normal Rust enums, with extra
//! [`#[frame::event]`](frame::pallet_macros::event) and
//! [`#[frame::error]`](frame::pallet_macros::error) attributes attached.
#![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Event)]
#![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", Error)]
//!
//! One slightly custom part of this is the `#[pallet::generate_deposit(pub(super) fn
//! deposit_event)]` part. Without going into too much detail, in order for a pallet to emit events
//! to the rest of the system, it needs to do two things:
//! One slightly custom part of this is the [`#[pallet::generate_deposit(pub(super) fn
//! deposit_event)]`](frame::pallet_macros::generate_deposit) part. Without going into too
//! much detail, in order for a pallet to emit events to the rest of the system, it needs to do two
//! things:
//!
//! 1. Declare a type in its `Config` that refers to the overarching event type of the runtime. In
//! short, by doing this, the pallet is expressing an important bound: `type RuntimeEvent:
Expand All @@ -266,7 +268,8 @@
//! store it where needed.
//!
//! 2. But, doing this conversion and storing is too much to expect each pallet to define. FRAME
//! provides a default way of storing events, and this is what `pallet::generate_deposit` is doing.
//! provides a default way of storing events, and this is what
//! [`pallet::generate_deposit`](frame::pallet_macros::generate_deposit) is doing.
#![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", config_v2)]
//!
//! > These `Runtime*` types are better explained in
Expand All @@ -280,8 +283,9 @@
#![doc = docify::embed!("./src/guides/your_first_pallet/mod.rs", runtime_v2)]
//!
//! In this snippet, the actual `RuntimeEvent` type (right hand side of `type RuntimeEvent =
//! RuntimeEvent`) is generated by `construct_runtime`. An interesting way to inspect this type is
//! to see its definition in rust-docs:
//! RuntimeEvent`) is generated by
//! [`construct_runtime`](frame::runtime::prelude::construct_runtime). An interesting way to inspect
//! this type is to see its definition in rust-docs:
//! [`crate::guides::your_first_pallet::pallet_v2::tests::runtime_v2::RuntimeEvent`].
//!
//!
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ aquamarine = { version = "0.5.0" }
[dev-dependencies]
assert_matches = "1.3.0"
pretty_assertions = "1.2.1"
sp-timestamp = { path = "../../primitives/timestamp", default-features = false }
frame-system = { path = "../system" }
sp-crypto-hashing = { path = "../../primitives/crypto/hashing" }

Expand Down Expand Up @@ -96,6 +97,7 @@ std = [
"sp-std/std",
"sp-tracing/std",
"sp-weights/std",
"sp-timestamp/std"
]
runtime-benchmarks = [
"frame-system/runtime-benchmarks",
Expand Down
Loading

0 comments on commit b0741d4

Please sign in to comment.