Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Jul 3, 2023
1 parent eec1333 commit 1d58dc9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 62 deletions.
4 changes: 2 additions & 2 deletions packages/std/src/errors/std_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ pub enum CoinsError {

impl From<CoinsError> for StdError {
fn from(value: CoinsError) -> Self {
Self::generic_err(format!("Creating Coins: {}", value))
Self::generic_err(format!("Creating Coins: {value}"))
}
}

Expand All @@ -629,7 +629,7 @@ impl From<std::num::ParseIntError> for CoinFromStrError {

impl From<CoinFromStrError> for StdError {
fn from(value: CoinFromStrError) -> Self {
Self::generic_err(format!("Parsing Coin: {}", value))
Self::generic_err(format!("Parsing Coin: {value}"))
}
}

Expand Down
24 changes: 9 additions & 15 deletions packages/std/src/math/int128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl FromStr for Int128 {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.parse::<i128>() {
Ok(u) => Ok(Self(u)),
Err(e) => Err(StdError::generic_err(format!("Parsing Int128: {}", e))),
Err(e) => Err(StdError::generic_err(format!("Parsing Int128: {e}"))),
}
}
}
Expand Down Expand Up @@ -399,10 +399,7 @@ impl Shr<u32> for Int128 {

fn shr(self, rhs: u32) -> Self::Output {
self.checked_shr(rhs).unwrap_or_else(|_| {
panic!(
"right shift error: {} is larger or equal than the number of bits in Int128",
rhs,
)
panic!("right shift error: {rhs} is larger or equal than the number of bits in Int128",)
})
}
}
Expand All @@ -413,10 +410,7 @@ impl Shl<u32> for Int128 {

fn shl(self, rhs: u32) -> Self::Output {
self.checked_shl(rhs).unwrap_or_else(|_| {
panic!(
"left shift error: {} is larger or equal than the number of bits in Int128",
rhs,
)
panic!("left shift error: {rhs} is larger or equal than the number of bits in Int128",)
})
}
}
Expand Down Expand Up @@ -483,7 +477,7 @@ impl<'de> de::Visitor<'de> for Int128Visitor {
where
E: de::Error,
{
Int128::try_from(v).map_err(|e| E::custom(format!("invalid Int128 '{}' - {}", v, e)))
Int128::try_from(v).map_err(|e| E::custom(format!("invalid Int128 '{v}' - {e}")))
}
}

Expand Down Expand Up @@ -608,25 +602,25 @@ mod tests {
#[test]
fn int128_implements_display() {
let a = Int128::from(12345u32);
assert_eq!(format!("Embedded: {}", a), "Embedded: 12345");
assert_eq!(format!("Embedded: {a}"), "Embedded: 12345");
assert_eq!(a.to_string(), "12345");

let a = Int128::from(-12345i32);
assert_eq!(format!("Embedded: {}", a), "Embedded: -12345");
assert_eq!(format!("Embedded: {a}"), "Embedded: -12345");
assert_eq!(a.to_string(), "-12345");

let a = Int128::zero();
assert_eq!(format!("Embedded: {}", a), "Embedded: 0");
assert_eq!(format!("Embedded: {a}"), "Embedded: 0");
assert_eq!(a.to_string(), "0");
}

#[test]
fn int128_display_padding_works() {
let a = Int128::from(123u64);
assert_eq!(format!("Embedded: {:05}", a), "Embedded: 00123");
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

let a = Int128::from(-123i64);
assert_eq!(format!("Embedded: {:05}", a), "Embedded: -0123");
assert_eq!(format!("Embedded: {a:05}"), "Embedded: -0123");
}

#[test]
Expand Down
24 changes: 9 additions & 15 deletions packages/std/src/math/int256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl FromStr for Int256 {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match I256::from_str_radix(s, 10) {
Ok(u) => Ok(Self(u)),
Err(e) => Err(StdError::generic_err(format!("Parsing Int256: {}", e))),
Err(e) => Err(StdError::generic_err(format!("Parsing Int256: {e}"))),
}
}
}
Expand Down Expand Up @@ -471,10 +471,7 @@ impl Shr<u32> for Int256 {

fn shr(self, rhs: u32) -> Self::Output {
self.checked_shr(rhs).unwrap_or_else(|_| {
panic!(
"right shift error: {} is larger or equal than the number of bits in Int256",
rhs,
)
panic!("right shift error: {rhs} is larger or equal than the number of bits in Int256",)
})
}
}
Expand All @@ -485,10 +482,7 @@ impl Shl<u32> for Int256 {

fn shl(self, rhs: u32) -> Self::Output {
self.checked_shl(rhs).unwrap_or_else(|_| {
panic!(
"left shift error: {} is larger or equal than the number of bits in Int256",
rhs,
)
panic!("left shift error: {rhs} is larger or equal than the number of bits in Int256",)
})
}
}
Expand Down Expand Up @@ -555,7 +549,7 @@ impl<'de> de::Visitor<'de> for Int256Visitor {
where
E: de::Error,
{
Int256::try_from(v).map_err(|e| E::custom(format!("invalid Int256 '{}' - {}", v, e)))
Int256::try_from(v).map_err(|e| E::custom(format!("invalid Int256 '{v}' - {e}")))
}
}

Expand Down Expand Up @@ -673,25 +667,25 @@ mod tests {
#[test]
fn int256_implements_display() {
let a = Int256::from(12345u32);
assert_eq!(format!("Embedded: {}", a), "Embedded: 12345");
assert_eq!(format!("Embedded: {a}"), "Embedded: 12345");
assert_eq!(a.to_string(), "12345");

let a = Int256::from(-12345i32);
assert_eq!(format!("Embedded: {}", a), "Embedded: -12345");
assert_eq!(format!("Embedded: {a}"), "Embedded: -12345");
assert_eq!(a.to_string(), "-12345");

let a = Int256::zero();
assert_eq!(format!("Embedded: {}", a), "Embedded: 0");
assert_eq!(format!("Embedded: {a}"), "Embedded: 0");
assert_eq!(a.to_string(), "0");
}

#[test]
fn int256_display_padding_works() {
let a = Int256::from(123u64);
assert_eq!(format!("Embedded: {:05}", a), "Embedded: 00123");
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

let a = Int256::from(-123i64);
assert_eq!(format!("Embedded: {:05}", a), "Embedded: -0123");
assert_eq!(format!("Embedded: {a:05}"), "Embedded: -0123");
}

#[test]
Expand Down
24 changes: 9 additions & 15 deletions packages/std/src/math/int512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl FromStr for Int512 {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match I512::from_str_radix(s, 10) {
Ok(u) => Ok(Self(u)),
Err(e) => Err(StdError::generic_err(format!("Parsing Int512: {}", e))),
Err(e) => Err(StdError::generic_err(format!("Parsing Int512: {e}"))),
}
}
}
Expand Down Expand Up @@ -504,10 +504,7 @@ impl Shr<u32> for Int512 {

fn shr(self, rhs: u32) -> Self::Output {
self.checked_shr(rhs).unwrap_or_else(|_| {
panic!(
"right shift error: {} is larger or equal than the number of bits in Int512",
rhs,
)
panic!("right shift error: {rhs} is larger or equal than the number of bits in Int512",)
})
}
}
Expand All @@ -518,10 +515,7 @@ impl Shl<u32> for Int512 {

fn shl(self, rhs: u32) -> Self::Output {
self.checked_shl(rhs).unwrap_or_else(|_| {
panic!(
"left shift error: {} is larger or equal than the number of bits in Int512",
rhs,
)
panic!("left shift error: {rhs} is larger or equal than the number of bits in Int512",)
})
}
}
Expand Down Expand Up @@ -588,7 +582,7 @@ impl<'de> de::Visitor<'de> for Int512Visitor {
where
E: de::Error,
{
Int512::try_from(v).map_err(|e| E::custom(format!("invalid Int512 '{}' - {}", v, e)))
Int512::try_from(v).map_err(|e| E::custom(format!("invalid Int512 '{v}' - {e}")))
}
}

Expand Down Expand Up @@ -712,25 +706,25 @@ mod tests {
#[test]
fn int512_implements_display() {
let a = Int512::from(12345u32);
assert_eq!(format!("Embedded: {}", a), "Embedded: 12345");
assert_eq!(format!("Embedded: {a}"), "Embedded: 12345");
assert_eq!(a.to_string(), "12345");

let a = Int512::from(-12345i32);
assert_eq!(format!("Embedded: {}", a), "Embedded: -12345");
assert_eq!(format!("Embedded: {a}"), "Embedded: -12345");
assert_eq!(a.to_string(), "-12345");

let a = Int512::zero();
assert_eq!(format!("Embedded: {}", a), "Embedded: 0");
assert_eq!(format!("Embedded: {a}"), "Embedded: 0");
assert_eq!(a.to_string(), "0");
}

#[test]
fn int512_display_padding_works() {
let a = Int512::from(123u64);
assert_eq!(format!("Embedded: {:05}", a), "Embedded: 00123");
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

let a = Int512::from(-123i64);
assert_eq!(format!("Embedded: {:05}", a), "Embedded: -0123");
assert_eq!(format!("Embedded: {a:05}"), "Embedded: -0123");
}

#[test]
Expand Down
24 changes: 9 additions & 15 deletions packages/std/src/math/int64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl FromStr for Int64 {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.parse::<i64>() {
Ok(u) => Ok(Self(u)),
Err(e) => Err(StdError::generic_err(format!("Parsing Int64: {}", e))),
Err(e) => Err(StdError::generic_err(format!("Parsing Int64: {e}"))),
}
}
}
Expand Down Expand Up @@ -375,10 +375,7 @@ impl Shr<u32> for Int64 {

fn shr(self, rhs: u32) -> Self::Output {
self.checked_shr(rhs).unwrap_or_else(|_| {
panic!(
"right shift error: {} is larger or equal than the number of bits in Int64",
rhs,
)
panic!("right shift error: {rhs} is larger or equal than the number of bits in Int64",)
})
}
}
Expand All @@ -389,10 +386,7 @@ impl Shl<u32> for Int64 {

fn shl(self, rhs: u32) -> Self::Output {
self.checked_shl(rhs).unwrap_or_else(|_| {
panic!(
"left shift error: {} is larger or equal than the number of bits in Int64",
rhs,
)
panic!("left shift error: {rhs} is larger or equal than the number of bits in Int64",)
})
}
}
Expand Down Expand Up @@ -459,7 +453,7 @@ impl<'de> de::Visitor<'de> for Int64Visitor {
where
E: de::Error,
{
Int64::try_from(v).map_err(|e| E::custom(format!("invalid Int64 '{}' - {}", v, e)))
Int64::try_from(v).map_err(|e| E::custom(format!("invalid Int64 '{v}' - {e}")))
}
}

Expand Down Expand Up @@ -578,25 +572,25 @@ mod tests {
#[test]
fn int64_implements_display() {
let a = Int64::from(12345u32);
assert_eq!(format!("Embedded: {}", a), "Embedded: 12345");
assert_eq!(format!("Embedded: {a}"), "Embedded: 12345");
assert_eq!(a.to_string(), "12345");

let a = Int64::from(-12345i32);
assert_eq!(format!("Embedded: {}", a), "Embedded: -12345");
assert_eq!(format!("Embedded: {a}"), "Embedded: -12345");
assert_eq!(a.to_string(), "-12345");

let a = Int64::zero();
assert_eq!(format!("Embedded: {}", a), "Embedded: 0");
assert_eq!(format!("Embedded: {a}"), "Embedded: 0");
assert_eq!(a.to_string(), "0");
}

#[test]
fn int64_display_padding_works() {
let a = Int64::from(123i64);
assert_eq!(format!("Embedded: {:05}", a), "Embedded: 00123");
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

let a = Int64::from(-123i64);
assert_eq!(format!("Embedded: {:05}", a), "Embedded: -0123");
assert_eq!(format!("Embedded: {a:05}"), "Embedded: -0123");
}

#[test]
Expand Down

0 comments on commit 1d58dc9

Please sign in to comment.