mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
Clippy arithmetic new (#8282)
* optimize code * fix clippy replace = with += or %= * fix redundant closure found warning * redundant field names in struct initialization * fix clippy warning and optimize code * fix clippy warning * fix clippy warning * fix test error
This commit is contained in:
@@ -92,7 +92,7 @@ pub trait FixedPointNumber:
|
||||
///
|
||||
/// Returns `None` if `int` exceeds accuracy.
|
||||
fn checked_from_integer(int: Self::Inner) -> Option<Self> {
|
||||
int.checked_mul(&Self::DIV).map(|inner| Self::from_inner(inner))
|
||||
int.checked_mul(&Self::DIV).map(Self::from_inner)
|
||||
}
|
||||
|
||||
/// Creates `self` from a rational number. Equal to `n / d`.
|
||||
@@ -119,7 +119,7 @@ pub trait FixedPointNumber:
|
||||
|
||||
multiply_by_rational(n.value, Self::DIV.unique_saturated_into(), d.value).ok()
|
||||
.and_then(|value| from_i129(I129 { value, negative }))
|
||||
.map(|inner| Self::from_inner(inner))
|
||||
.map(Self::from_inner)
|
||||
}
|
||||
|
||||
/// Checked multiplication for integer type `N`. Equal to `self * n`.
|
||||
@@ -184,7 +184,7 @@ pub trait FixedPointNumber:
|
||||
if inner >= Self::Inner::zero() {
|
||||
self
|
||||
} else {
|
||||
Self::from_inner(inner.checked_neg().unwrap_or_else(|| Self::Inner::max_value()))
|
||||
Self::from_inner(inner.checked_neg().unwrap_or_else(Self::Inner::max_value))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ pub trait FixedPointNumber:
|
||||
self.into_inner().checked_div(&Self::DIV)
|
||||
.expect("panics only if DIV is zero, DIV is not zero; qed")
|
||||
.checked_mul(&Self::DIV)
|
||||
.map(|inner| Self::from_inner(inner))
|
||||
.map(Self::from_inner)
|
||||
.expect("can not overflow since fixed number is >= integer part")
|
||||
}
|
||||
|
||||
@@ -254,12 +254,10 @@ pub trait FixedPointNumber:
|
||||
fn ceil(self) -> Self {
|
||||
if self.is_negative() {
|
||||
self.trunc()
|
||||
} else if self.frac() == Self::zero() {
|
||||
self
|
||||
} else {
|
||||
if self.frac() == Self::zero() {
|
||||
self
|
||||
} else {
|
||||
self.saturating_add(Self::one()).trunc()
|
||||
}
|
||||
self.saturating_add(Self::one()).trunc()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,12 +279,10 @@ pub trait FixedPointNumber:
|
||||
let n = self.frac().saturating_mul(Self::saturating_from_integer(10));
|
||||
if n < Self::saturating_from_integer(5) {
|
||||
self.trunc()
|
||||
} else if self.is_positive() {
|
||||
self.saturating_add(Self::one()).trunc()
|
||||
} else {
|
||||
if self.is_positive() {
|
||||
self.saturating_add(Self::one()).trunc()
|
||||
} else {
|
||||
self.saturating_sub(Self::one()).trunc()
|
||||
}
|
||||
self.saturating_sub(Self::one()).trunc()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -585,7 +581,7 @@ macro_rules! implement_fixed {
|
||||
{
|
||||
use sp_std::str::FromStr;
|
||||
let s = String::deserialize(deserializer)?;
|
||||
$name::from_str(&s).map_err(|err_str| de::Error::custom(err_str))
|
||||
$name::from_str(&s).map_err(de::Error::custom)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user