Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
20e80966
Commit
20e80966
authored
5 years ago
by
Gavin Wood
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Introduce the `Get` trait and type_parameter. (#2565)
parent
21773b3a
Branches
gh-readonly-queue/master/pr-5515-325df541392fe04f95803a8cb5364cdbda741c16
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/srml/support/src/lib.rs
+3
-3
3 additions, 3 deletions
substrate/srml/support/src/lib.rs
substrate/srml/support/src/traits.rs
+39
-0
39 additions, 0 deletions
substrate/srml/support/src/traits.rs
with
42 additions
and
3 deletions
substrate/srml/support/src/lib.rs
+
3
−
3
View file @
20e80966
...
...
@@ -61,7 +61,7 @@ pub use self::storage::{StorageList, StorageValue, StorageMap, EnumerableStorage
pub
use
self
::
hashable
::
Hashable
;
pub
use
self
::
dispatch
::{
Parameter
,
Dispatchable
,
Callable
,
IsSubType
};
pub
use
self
::
double_map
::
StorageDoubleMapWithHasher
;
pub
use
runtime_io
::
print
;
pub
use
runtime_io
::
{
print
,
storage_root
}
;
#[doc(inline)]
pub
use
srml_support_procedural
::
decl_storage
;
...
...
@@ -96,9 +96,9 @@ macro_rules! ensure {
#[cfg(feature
=
"std"
)]
macro_rules!
assert_noop
{
(
$x:expr
,
$y:expr
)
=>
{
let
h
=
runtime_io
::
storage_root
();
let
h
=
$crate
::
storage_root
();
$crate
::
assert_err!
(
$x
,
$y
);
assert_eq!
(
h
,
runtime_io
::
storage_root
());
assert_eq!
(
h
,
$crate
::
storage_root
());
}
}
...
...
This diff is collapsed.
Click to expand it.
substrate/srml/support/src/traits.rs
+
39
−
0
View file @
20e80966
...
...
@@ -22,6 +22,45 @@ use crate::runtime_primitives::traits::{
MaybeSerializeDebug
,
SimpleArithmetic
};
/// New trait for querying a single fixed value from a type.
pub
trait
Get
<
T
>
{
/// Return a constant value.
fn
get
()
->
T
;
}
/// Macro for easily creating a new implementation of the `Get` trait. Use similarly to
/// how you would declare a `const`:
///
/// ```no_compile
/// parameter_types! {
/// pub const Argument: u64 = 42;
/// }
/// trait Config {
/// type Parameter: Get<u64>;
/// }
/// struct Runtime;
/// impl Config for Runtime {
/// type Parameter = Argument;
/// }
/// ```
#[macro_export]
macro_rules!
parameter_types
{
(
pub
const
$name:ident
:
$type:ty
=
$value:expr
;
$
(
$rest:tt
)
*
)
=>
(
pub
struct
$name
;
parameter_types!
{
IMPL
$name
,
$type
,
$value
}
parameter_types!
{
$
(
$rest
)
*
}
);
(
const
$name:ident
:
$type:ty
=
$value:expr
;
$
(
$rest:tt
)
*
)
=>
(
struct
$name
;
parameter_types!
{
IMPL
$name
,
$type
,
$value
}
parameter_types!
{
$
(
$rest
)
*
}
);
()
=>
();
(
IMPL
$name:ident
,
$type:ty
,
$value:expr
)
=>
{
impl
$crate
::
traits
::
Get
<
$type
>
for
$name
{
fn
get
()
->
$type
{
$value
}
}
}
}
/// The account with the given id was killed.
pub
trait
OnFreeBalanceZero
<
AccountId
>
{
/// The account was the given id was killed.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment