mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Fix new clippy lints (#2036)
## Issue Addressed NA ## Proposed Changes Fixes new clippy lints in the whole project (mainly [manual_strip](https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip) and [unnecessary_lazy_evaluations](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations)). Furthermore, removes `to_string()` calls on literals when used with the `?`-operator.
This commit is contained in:
@@ -13,8 +13,8 @@ pub fn encode<T: AsRef<[u8]>>(data: T) -> String {
|
||||
|
||||
/// Decode `data` from a 0x-prefixed hex string.
|
||||
pub fn decode(s: &str) -> Result<Vec<u8>, String> {
|
||||
if s.starts_with("0x") {
|
||||
hex::decode(&s[2..]).map_err(|e| format!("invalid hex: {:?}", e))
|
||||
if let Some(stripped) = s.strip_prefix("0x") {
|
||||
hex::decode(stripped).map_err(|e| format!("invalid hex: {:?}", e))
|
||||
} else {
|
||||
Err("hex must have 0x prefix".to_string())
|
||||
}
|
||||
@@ -33,8 +33,8 @@ impl<'de> Visitor<'de> for PrefixedHexVisitor {
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
if value.starts_with("0x") {
|
||||
Ok(hex::decode(&value[2..])
|
||||
if let Some(stripped) = value.strip_prefix("0x") {
|
||||
Ok(hex::decode(stripped)
|
||||
.map_err(|e| de::Error::custom(format!("invalid hex ({:?})", e)))?)
|
||||
} else {
|
||||
Err(de::Error::custom("missing 0x prefix"))
|
||||
|
||||
Reference in New Issue
Block a user