Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Adds ConstGet trait and impl in parameter types #13391

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub use paste;
pub use scale_info;
#[cfg(feature = "std")]
pub use serde;
#[doc(hidden)]
pub use sp_core::ConstGet;
pub use sp_core::Void;
#[doc(hidden)]
pub use sp_core_hashing_proc_macro;
Expand Down Expand Up @@ -338,6 +340,12 @@ macro_rules! parameter_types {
Self::get()
}
}

impl<_I: From<$type> $(, $ty_params)*> $crate::ConstGet<_I> for $name< $($ty_params),* > {
fn get() -> _I {
_I::from(Self::get())
}
}
};
(IMPL $name:ident, $type:ty, $value:expr $(, $ty_params:ident)*) => {
impl< $($ty_params),* > $name< $($ty_params),* > {
Expand Down Expand Up @@ -1484,6 +1492,7 @@ pub mod pallet_prelude {
};
pub use sp_std::marker::PhantomData;
pub use sp_weights::Weight;
pub use sp_core::ConstGet;
}

/// The `pallet` attribute macro defines a pallet that can be used with
Expand Down
8 changes: 8 additions & 0 deletions primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,11 @@ macro_rules! generate_feature_enabled_macro {
}
};
}

/// A trait for querying a single value from a type.
///
/// The value should be a constant.
pub trait ConstGet<T> {
/// Return the constant value.
fn get() -> T;
}