mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 14:37:57 +00:00
Make Get<T> const friendly + Clean the runtime files a bit. (#6132)
* Make Get const friendly * Better doc * Grumble * Better doc * Clean runtime files more
This commit is contained in:
@@ -383,7 +383,6 @@ macro_rules! implement_per_thing {
|
||||
impl $name {
|
||||
/// From an explicitly defined number of parts per maximum of the type.
|
||||
///
|
||||
/// This can be called at compile time.
|
||||
// needed only for peru16. Since peru16 is the only type in which $max ==
|
||||
// $type::max_value(), rustc is being a smart-a** here by warning that the comparison
|
||||
// is not needed.
|
||||
@@ -399,9 +398,9 @@ macro_rules! implement_per_thing {
|
||||
Self(([x, 100][(x > 100) as usize] as $upper_type * $max as $upper_type / 100) as $type)
|
||||
}
|
||||
|
||||
/// See [`PerThing::one`].
|
||||
pub fn one() -> Self {
|
||||
<Self as PerThing>::one()
|
||||
/// See [`PerThing::one`]
|
||||
pub const fn one() -> Self {
|
||||
Self::from_parts($max)
|
||||
}
|
||||
|
||||
/// See [`PerThing::is_one`].
|
||||
@@ -410,8 +409,8 @@ macro_rules! implement_per_thing {
|
||||
}
|
||||
|
||||
/// See [`PerThing::zero`].
|
||||
pub fn zero() -> Self {
|
||||
<Self as PerThing>::zero()
|
||||
pub const fn zero() -> Self {
|
||||
Self::from_parts(0)
|
||||
}
|
||||
|
||||
/// See [`PerThing::is_zero`].
|
||||
@@ -420,8 +419,8 @@ macro_rules! implement_per_thing {
|
||||
}
|
||||
|
||||
/// See [`PerThing::deconstruct`].
|
||||
pub fn deconstruct(self) -> $type {
|
||||
PerThing::deconstruct(self)
|
||||
pub const fn deconstruct(self) -> $type {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// See [`PerThing::square`].
|
||||
@@ -1130,6 +1129,18 @@ macro_rules! implement_per_thing {
|
||||
1,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[allow(unused)]
|
||||
fn const_fns_work() {
|
||||
const C1: $name = $name::from_percent(50);
|
||||
const C2: $name = $name::one();
|
||||
const C3: $name = $name::zero();
|
||||
const C4: $name = $name::from_parts(1);
|
||||
|
||||
// deconstruct is also const, hence it can be called in const rhs.
|
||||
const C5: bool = C1.deconstruct() == 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user