pub struct Permill(/* private fields */);
Expand description
Re-export top-level arithmetic stuff. A fixed point representation of a number in the range [0, 1].
Parts per Million
Implementations§
Source§impl Permill
impl Permill
Sourcepub const fn from_parts(parts: u32) -> Permill
pub const fn from_parts(parts: u32) -> Permill
From an explicitly defined number of parts per maximum of the type.
Sourcepub const fn from_percent(x: u32) -> Permill
pub const fn from_percent(x: u32) -> Permill
Converts a percent into Self
. Equal to x / 100
.
This can be created at compile time.
Sourcepub const fn one() -> Permill
pub const fn one() -> Permill
See PerThing::one
Sourcepub fn is_one(&self) -> bool
pub fn is_one(&self) -> bool
See PerThing::is_one
.
Sourcepub const fn zero() -> Permill
pub const fn zero() -> Permill
See PerThing::zero
.
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
See PerThing::is_zero
.
Sourcepub const fn deconstruct(self) -> u32
pub const fn deconstruct(self) -> u32
Sourcepub fn square(self) -> Permill
pub fn square(self) -> Permill
See PerThing::square
.
Sourcepub fn from_fraction(x: f64) -> Permill
pub fn from_fraction(x: f64) -> Permill
Sourcepub fn from_rational_approximation<N>(p: N, q: N) -> Permill
pub fn from_rational_approximation<N>(p: N, q: N) -> Permill
Sourcepub fn mul_floor<N>(self, b: N) -> N
pub fn mul_floor<N>(self, b: N) -> N
See PerThing::mul_floor
.
Sourcepub fn mul_ceil<N>(self, b: N) -> N
pub fn mul_ceil<N>(self, b: N) -> N
See PerThing::mul_ceil
.
Sourcepub fn saturating_reciprocal_mul<N>(self, b: N) -> N
pub fn saturating_reciprocal_mul<N>(self, b: N) -> N
Sourcepub fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N
pub fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N
Sourcepub fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N
pub fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N
Trait Implementations§
Source§impl CompactAs for Permill
Implementation makes any compact encoding of PerThing::Inner
valid,
when decoding it will saturate up to PerThing::ACCURACY
.
impl CompactAs for Permill
Implementation makes any compact encoding of PerThing::Inner
valid,
when decoding it will saturate up to PerThing::ACCURACY
.
Source§impl Decode for Permill
impl Decode for Permill
Source§impl<'de> Deserialize<'de> for Permill
impl<'de> Deserialize<'de> for Permill
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Permill, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Permill, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Encode for Permill
impl Encode for Permill
Source§fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Source§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Source§impl<N> Mul<N> for Permill
Non-overflow multiplication.
impl<N> Mul<N> for Permill
Non-overflow multiplication.
This is tailored to be used with a balance type.
Source§impl Ord for Permill
impl Ord for Permill
Source§impl PartialOrd for Permill
impl PartialOrd for Permill
Source§impl PerThing for Permill
impl PerThing for Permill
Source§fn deconstruct(self) -> <Permill as PerThing>::Inner
fn deconstruct(self) -> <Permill as PerThing>::Inner
Consume self and return the number of parts per thing.
Source§fn from_parts(parts: <Permill as PerThing>::Inner) -> Permill
fn from_parts(parts: <Permill as PerThing>::Inner) -> Permill
Build this type from a number of parts per thing.
Source§fn from_fraction(x: f64) -> Permill
fn from_fraction(x: f64) -> Permill
NOTE: saturate to 0 or 1 if x is beyond [0, 1]
Source§const ACCURACY: <Permill as PerThing>::Inner = {transmute(0x000f4240): <arithmetic::Permill as arithmetic::PerThing>::Inner}
const ACCURACY: <Permill as PerThing>::Inner = {transmute(0x000f4240): <arithmetic::Permill as arithmetic::PerThing>::Inner}
Source§type Upper = u64
type Upper = u64
Self::Inner
, used to avoid overflow in some computations.
It must be able to compute ACCURACY^2
.Source§fn from_rational_approximation<N>(p: N, q: N) -> Permill
fn from_rational_approximation<N>(p: N, q: N) -> Permill
p/q
into a per-thing fraction. This will never overflow. Read moreSource§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.Source§fn mul_floor<N>(self, b: N) -> N
fn mul_floor<N>(self, b: N) -> N
Mul
rounds to the
nearest whole number. Read moreSource§fn mul_ceil<N>(self, b: N) -> N
fn mul_ceil<N>(self, b: N) -> N
Mul
rounds to the nearest whole number. Read moreSource§fn saturating_reciprocal_mul<N>(self, b: N) -> N
fn saturating_reciprocal_mul<N>(self, b: N) -> N
self
. The result is rounded to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read moreSource§fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N
fn saturating_reciprocal_mul_floor<N>(self, b: N) -> N
self
. The result is rounded down to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read moreSource§fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N
fn saturating_reciprocal_mul_ceil<N>(self, b: N) -> N
self
. The result is rounded up to the
nearest whole number and saturates at the numeric bounds instead of overflowing. Read moreSource§impl Saturating for Permill
impl Saturating for Permill
Source§fn saturating_add(self, rhs: Permill) -> Permill
fn saturating_add(self, rhs: Permill) -> Permill
Saturating addition. Compute self + rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossless if it does not saturate.
Source§fn saturating_sub(self, rhs: Permill) -> Permill
fn saturating_sub(self, rhs: Permill) -> Permill
Saturating subtraction. Compute self - rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossless if it does not saturate.
Source§fn saturating_mul(self, rhs: Permill) -> Permill
fn saturating_mul(self, rhs: Permill) -> Permill
Saturating multiply. Compute self * rhs
, saturating at the numeric bounds instead of
overflowing. This operation is lossy.
Source§fn saturating_pow(self, exp: usize) -> Permill
fn saturating_pow(self, exp: usize) -> Permill
Saturating exponentiation. Computes self.pow(exp)
, saturating at the numeric
bounds instead of overflowing. This operation is lossy.
Source§impl Serialize for Permill
impl Serialize for Permill
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Copy for Permill
impl EncodeLike for Permill
impl Eq for Permill
impl StructuralPartialEq for Permill
Auto Trait Implementations§
impl Freeze for Permill
impl RefUnwindSafe for Permill
impl Send for Permill
impl Sync for Permill
impl Unpin for Permill
impl UnwindSafe for Permill
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DecodeLimit for Twhere
T: Decode,
impl<T> DecodeLimit for Twhere
T: Decode,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> HasCompact for T
impl<T> HasCompact for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
Source§impl<T> LowerBounded for Twhere
T: Bounded,
impl<T> LowerBounded for Twhere
T: Bounded,
Source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
Source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
Source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T
. Read moreSource§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
Source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.Source§impl<T, S> UniqueSaturatedFrom<T> for S
impl<T, S> UniqueSaturatedFrom<T> for S
Source§fn unique_saturated_from(t: T) -> S
fn unique_saturated_from(t: T) -> S
T
into an equivalent instance of Self
.Source§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
Source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.