pub type OnChainAccuracy = Perbill;
Expand description
The accuracy type used for genesis election provider;
Aliased Type§
struct OnChainAccuracy(/* private fields */);
Implementations
§impl Perbill
impl Perbill
pub const fn from_parts(parts: u32) -> Perbill
pub const fn from_parts(parts: u32) -> Perbill
From an explicitly defined number of parts per maximum of the type.
pub const fn from_percent(x: u32) -> Perbill
pub const fn from_percent(x: u32) -> Perbill
Converts a percent into Self
. Equal to x / 100
.
This can be created at compile time.
pub const fn one() -> Perbill
pub const fn one() -> Perbill
See [PerThing::one
]
pub const fn zero() -> Perbill
pub const fn zero() -> Perbill
See [PerThing::zero
].
pub const fn deconstruct(self) -> u32
pub const fn deconstruct(self) -> u32
See [PerThing::deconstruct
].
pub fn square(self) -> Perbill
pub fn square(self) -> Perbill
See [PerThing::square
].
pub fn from_float(x: f64) -> Perbill
pub fn from_float(x: f64) -> Perbill
See [PerThing::from_float
].
pub fn from_rational_approximation<N>(p: N, q: N) -> Perbill
👎Deprecated: Use PerThing::from_rational
instead
pub fn from_rational_approximation<N>(p: N, q: N) -> Perbill
PerThing::from_rational
insteadSee [PerThing::from_rational
].
pub fn from_rational<N>(p: N, q: N) -> Perbill
pub fn from_rational<N>(p: N, q: N) -> Perbill
See [PerThing::from_rational
].
pub fn mul_floor<N>(self, b: N) -> N
pub fn mul_floor<N>(self, b: N) -> N
See [PerThing::mul_floor
].
pub fn mul_ceil<N>(self, b: N) -> N
pub fn mul_ceil<N>(self, b: N) -> N
See [PerThing::mul_ceil
].
pub fn saturating_reciprocal_mul<N>(self, b: N) -> N
pub fn saturating_reciprocal_mul<N>(self, b: N) -> N
See [PerThing::saturating_reciprocal_mul
].
pub fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N
pub fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N
See [PerThing::saturating_reciprocal_mul_floor
].
pub fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N
pub fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N
See [PerThing::saturating_reciprocal_mul_ceil
].
pub fn saturating_div(self, rhs: Perbill, r: Rounding) -> Perbill
pub fn saturating_div(self, rhs: Perbill, r: Rounding) -> Perbill
Saturating division. Compute self / rhs
, saturating at one if rhs < self
.
The rounding
method must be specified. e.g.:
let pc = |x| Percent::from_percent(x);
assert_eq!(
pc(2).saturating_div(pc(3), Down),
pc(66),
);
assert_eq!(
pc(1).saturating_div(pc(3), NearestPrefUp),
pc(33),
);
assert_eq!(
pc(2).saturating_div(pc(3), NearestPrefDown),
pc(67),
);
assert_eq!(
pc(1).saturating_div(pc(3), Up),
pc(34),
);
§impl Perbill
impl Perbill
pub const fn from_perthousand(x: u32) -> Perbill
pub const fn from_perthousand(x: u32) -> Perbill
Converts a percent into Self
. Equal to x / 1000
.
This can be created at compile time.
Trait Implementations
§impl CheckedAdd for Perbill
impl CheckedAdd for Perbill
§fn checked_add(&self, rhs: &Perbill) -> Option<Perbill>
fn checked_add(&self, rhs: &Perbill) -> Option<Perbill>
None
is
returned.§impl CheckedMul for Perbill
impl CheckedMul for Perbill
§Note
CheckedMul will never fail for PerThings.
§fn checked_mul(&self, rhs: &Perbill) -> Option<Perbill>
fn checked_mul(&self, rhs: &Perbill) -> Option<Perbill>
None
is returned.§impl CheckedSub for Perbill
impl CheckedSub for Perbill
§fn checked_sub(&self, v: &Perbill) -> Option<Perbill>
fn checked_sub(&self, v: &Perbill) -> Option<Perbill>
None
is returned.§impl CompactAs for Perbill
impl CompactAs for Perbill
Implementation makes any compact encoding of PerThing::Inner
valid,
when decoding it will saturate up to PerThing::ACCURACY
.
§impl Decode for Perbill
impl Decode for Perbill
§fn decode<I>(input: &mut I) -> Result<Perbill, Error>where
I: Input,
fn decode<I>(input: &mut I) -> Result<Perbill, Error>where
I: Input,
§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
§fn skip<I>(input: &mut I) -> Result<(), Error>where
I: Input,
fn skip<I>(input: &mut I) -> Result<(), Error>where
I: Input,
§fn encoded_fixed_size() -> Option<usize>
fn encoded_fixed_size() -> Option<usize>
§impl<'de> Deserialize<'de> for Perbill
impl<'de> Deserialize<'de> for Perbill
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Perbill, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Perbill, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Encode for Perbill
impl Encode for Perbill
§fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)where
__CodecOutputEdqy: Output + ?Sized,
fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)where
__CodecOutputEdqy: Output + ?Sized,
§fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback>(
&self,
f: __CodecUsingEncodedCallback,
) -> __CodecOutputReturn
fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback>( &self, f: __CodecUsingEncodedCallback, ) -> __CodecOutputReturn
§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
§impl MaxEncodedLen for Perbill
impl MaxEncodedLen for Perbill
§fn max_encoded_len() -> usize
fn max_encoded_len() -> usize
§impl<N> Mul<N> for Perbill
impl<N> Mul<N> for Perbill
Non-overflow multiplication.
This is tailored to be used with a balance type.
§impl Ord for Perbill
impl Ord for Perbill
§impl PartialOrd for Perbill
impl PartialOrd for Perbill
§impl PerThing for Perbill
impl PerThing for Perbill
§fn deconstruct(self) -> <Perbill as PerThing>::Inner
fn deconstruct(self) -> <Perbill as PerThing>::Inner
Consume self and return the number of parts per thing.
§fn from_parts(parts: <Perbill as PerThing>::Inner) -> Perbill
fn from_parts(parts: <Perbill as PerThing>::Inner) -> Perbill
Build this type from a number of parts per thing.
§fn from_float(x: f64) -> Perbill
fn from_float(x: f64) -> Perbill
NOTE: saturate to 0 or 1 if x is beyond [0, 1]
§const ACCURACY: <Perbill as PerThing>::Inner = {transmute(0x3b9aca00): <sp_runtime::Perbill as sp_runtime::PerThing>::Inner}
const ACCURACY: <Perbill as PerThing>::Inner = {transmute(0x3b9aca00): <sp_runtime::Perbill as sp_runtime::PerThing>::Inner}
§type Upper = u64
type Upper = u64
Self::Inner
, used to avoid overflow in some computations.
It must be able to compute ACCURACY^2
.§fn from_rational_with_rounding<N>(
p: N,
q: N,
r: Rounding,
) -> Result<Perbill, ()>
fn from_rational_with_rounding<N>( p: N, q: N, r: Rounding, ) -> Result<Perbill, ()>
p/q
into a per-thing fraction. Read more§fn less_epsilon(self) -> Self
fn less_epsilon(self) -> Self
self
or self
if it is already zero.§fn try_less_epsilon(self) -> Result<Self, Self>
fn try_less_epsilon(self) -> Result<Self, Self>
self
or an error with the same value if self
is already
zero.§fn plus_epsilon(self) -> Self
fn plus_epsilon(self) -> Self
self
or self
if it is already one.§fn try_plus_epsilon(self) -> Result<Self, Self>
fn try_plus_epsilon(self) -> Result<Self, Self>
self
or an error with the same value if self
is already
one.§fn from_percent(x: Self::Inner) -> Self
fn from_percent(x: Self::Inner) -> Self
Self::from_parts(x * Self::ACCURACY / 100)
but more accurate and can cope with potential type overflows.§fn left_from_one(self) -> Self
fn left_from_one(self) -> Self
self
is saturating-subtracted from Self::one()
.§fn mul_floor<N>(self, b: N) -> Nwhere
N: MultiplyArg + UniqueSaturatedInto<Self::Inner>,
Self::Inner: Into<N>,
fn mul_floor<N>(self, b: N) -> Nwhere
N: MultiplyArg + UniqueSaturatedInto<Self::Inner>,
Self::Inner: Into<N>,
Mul
rounds to the
nearest whole number. Read more§fn mul_ceil<N>(self, b: N) -> Nwhere
N: MultiplyArg + UniqueSaturatedInto<Self::Inner>,
Self::Inner: Into<N>,
fn mul_ceil<N>(self, b: N) -> Nwhere
N: MultiplyArg + UniqueSaturatedInto<Self::Inner>,
Self::Inner: Into<N>,
Mul
rounds to the nearest whole number. Read more§fn saturating_reciprocal_mul<N>(self, b: N) -> Nwhere
N: ReciprocalArg + UniqueSaturatedInto<Self::Inner>,
Self::Inner: Into<N>,
fn saturating_reciprocal_mul<N>(self, b: N) -> Nwhere
N: ReciprocalArg + UniqueSaturatedInto<Self::Inner>,
Self::Inner: Into<N>,
self
. The result is rounded to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read more§fn saturating_reciprocal_mul_floor<N>(self, b: N) -> Nwhere
N: ReciprocalArg + UniqueSaturatedInto<Self::Inner>,
Self::Inner: Into<N>,
fn saturating_reciprocal_mul_floor<N>(self, b: N) -> Nwhere
N: ReciprocalArg + UniqueSaturatedInto<Self::Inner>,
Self::Inner: Into<N>,
self
. The result is rounded down to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read more§fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> Nwhere
N: ReciprocalArg + UniqueSaturatedInto<Self::Inner>,
Self::Inner: Into<N>,
fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> Nwhere
N: ReciprocalArg + UniqueSaturatedInto<Self::Inner>,
Self::Inner: Into<N>,
self
. The result is rounded up to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read more§fn from_rational<N>(p: N, q: N) -> Self
fn from_rational<N>(p: N, q: N) -> Self
p/q
into a per-thing fraction. This will never overflow. Read more§fn from_rational_approximation<N>(p: N, q: N) -> Self
fn from_rational_approximation<N>(p: N, q: N) -> Self
Self::from_rational
.§impl Saturating for Perbill
impl Saturating for Perbill
§fn saturating_add(self, rhs: Perbill) -> Perbill
fn saturating_add(self, rhs: Perbill) -> Perbill
Saturating addition. Compute self + rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossless if it does not saturate.
§fn saturating_sub(self, rhs: Perbill) -> Perbill
fn saturating_sub(self, rhs: Perbill) -> Perbill
Saturating subtraction. Compute self - rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossless if it does not saturate.
§fn saturating_mul(self, rhs: Perbill) -> Perbill
fn saturating_mul(self, rhs: Perbill) -> Perbill
Saturating multiply. Compute self * rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossy.
§fn saturating_pow(self, exp: usize) -> Perbill
fn saturating_pow(self, exp: usize) -> Perbill
Saturating exponentiation. Computes self.pow(exp)
, saturating at the numeric
bounds instead of overflowing. This operation is lossy.
§fn saturating_less_one(self) -> Selfwhere
Self: One,
fn saturating_less_one(self) -> Selfwhere
Self: One,
§fn saturating_plus_one(self) -> Selfwhere
Self: One,
fn saturating_plus_one(self) -> Selfwhere
Self: One,
§fn saturating_inc(&mut self)where
Self: One,
fn saturating_inc(&mut self)where
Self: One,
§fn saturating_dec(&mut self)where
Self: One,
fn saturating_dec(&mut self)where
Self: One,
§fn saturating_accrue(&mut self, amount: Self)where
Self: One,
fn saturating_accrue(&mut self, amount: Self)where
Self: One,
amount
, saturating.§fn saturating_reduce(&mut self, amount: Self)where
Self: One,
fn saturating_reduce(&mut self, amount: Self)where
Self: One,
amount
, saturating at zero.§impl SaturatingAdd for Perbill
impl SaturatingAdd for Perbill
§fn saturating_add(&self, v: &Perbill) -> Perbill
fn saturating_add(&self, v: &Perbill) -> Perbill
self + other
, saturating at the relevant high or low boundary of
the type.§impl SaturatingSub for Perbill
impl SaturatingSub for Perbill
§fn saturating_sub(&self, v: &Perbill) -> Perbill
fn saturating_sub(&self, v: &Perbill) -> Perbill
self - other
, saturating at the relevant high or low boundary of
the type.