Per-things trait. (#4904)

* Give perthigns the trait it always deserved.

* Make staking and phragmen work with the new generic per_thing

* Make everything work together 🔨

* a bit of cleanup

* Clean usage

* Bump.

* Fix name

* fix grumbles

* hopefully fix the ui test

* Some grumbles

* revamp traits again

* Better naming again.
This commit is contained in:
Kian Paimani
2020-02-13 13:09:33 +01:00
committed by GitHub
parent e6454eb091
commit c871eaacbc
42 changed files with 346 additions and 241 deletions
+3 -3
View File
@@ -16,7 +16,7 @@
//! Provides some utilities to define a piecewise linear function.
use crate::{Perbill, traits::{SimpleArithmetic, SaturatedConversion}};
use crate::{Perbill, PerThing, traits::{AtLeast32Bit, SaturatedConversion}};
use core::ops::Sub;
/// Piecewise Linear function in [0, 1] -> [0, 1].
@@ -35,7 +35,7 @@ fn abs_sub<N: Ord + Sub<Output=N> + Clone>(a: N, b: N) -> N where {
impl<'a> PiecewiseLinear<'a> {
/// Compute `f(n/d)*d` with `n <= d`. This is useful to avoid loss of precision.
pub fn calculate_for_fraction_times_denominator<N>(&self, n: N, d: N) -> N where
N: SimpleArithmetic + Clone
N: AtLeast32Bit + Clone
{
let n = n.min(d.clone());
@@ -79,7 +79,7 @@ impl<'a> PiecewiseLinear<'a> {
// This is guaranteed not to overflow on whatever values nor lose precision.
// `q` must be superior to zero.
fn multiply_by_rational_saturating<N>(value: N, p: u32, q: u32) -> N
where N: SimpleArithmetic + Clone
where N: AtLeast32Bit + Clone
{
let q = q.max(1);