Skip to content
Snippets Groups Projects
Commit cb1d076a authored by Éloïs's avatar Éloïs
Browse files

[style] comply to fmt & clippy 1.38

parent 9f0caf31
No related branches found
No related tags found
1 merge request!193Resolve "Migrate high-volume DBs to LMDB"
......@@ -167,19 +167,14 @@ impl Blockstamp {
let id = split.next().unwrap().parse::<u32>();
let hash = Hash::from_hex(split.next().unwrap())?;
if id.is_err() {
Err(BlockstampParseError::InvalidBlockNumber())
} else {
if let Ok(id) = id {
Ok(Blockstamp {
id: BlockNumber(id.unwrap()),
id: BlockNumber(id),
hash: BlockHash(hash),
})
} else {
Err(BlockstampParseError::InvalidBlockNumber())
}
}
}
/// Convert a `BlockUId` to its text format.
pub fn to_string(&self) -> String {
format!("{}", self)
}
}
......@@ -165,5 +165,4 @@ mod tests {
parse_json_transaction(&tx_json_value).expect("Fail to parse tx_json_value !")
);
}
}
......@@ -36,6 +36,21 @@ pub static MAX_API_FEATURES_COUNT: &usize = &2040;
/// ApiFeatures
pub struct ApiFeatures(pub Vec<u8>);
impl Display for ApiFeatures {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
if self.is_empty() {
write!(f, "")
} else {
let hex_str = hex::encode(self.0.clone());
if hex_str.len() == 2 {
write!(f, "0x{} ", &hex_str[1..])
} else {
write!(f, "0x{} ", hex_str)
}
}
}
}
impl ApiFeatures {
fn is_empty(&self) -> bool {
for byte in &self.0 {
......@@ -45,19 +60,6 @@ impl ApiFeatures {
}
true
}
fn to_string(&self) -> String {
if self.is_empty() {
String::from("")
} else {
let hex_str = hex::encode(self.0.clone());
if hex_str.len() == 2 {
format!("0x{} ", &hex_str[1..])
} else {
format!("0x{} ", hex_str)
}
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
......
......@@ -68,7 +68,7 @@ impl NetworkHeadMessageV2 {
pub fn to_human_string(&self, max_len: usize, uid: Option<String>) -> String {
let short_api = &self.api[4..];
if max_len > 85 && uid.is_some() {
if max_len > 85 {
format!(
"{node_id:8}-{pubkey:.8} {blockstamp:.16} {soft:9}:{ver:14} {pre:3} [{api:5}] {mer:02}:{mir:02} {uid}",
node_id = self.node_uuid.to_string(),
......@@ -80,7 +80,7 @@ impl NetworkHeadMessageV2 {
api = short_api,
mer = self.free_member_room.unwrap_or(0),
mir = self.free_mirror_room.unwrap_or(0),
uid = uid.unwrap(),
uid = uid.unwrap_or_default(),
)
} else if max_len > 75 {
format!(
......
......@@ -76,7 +76,8 @@ impl PeerCardV11 {
))
}
Rule::block_id => {
created_on = Some(BlockNumber(field.as_str().parse().unwrap())); // Grammar ensures that we have a digits string.
created_on = Some(BlockNumber(field.as_str().parse().unwrap()));
// Grammar ensures that we have a digits string.
}
Rule::endpoint_v2 => endpoints.push(EndpointV2::from_pest_pair(field)?),
Rule::ed25519_sig => {
......
......@@ -778,5 +778,4 @@ mod tests {
// Check that the root of the tree has shifted
assert_eq!(Some(TreeNodeId(1)), tree.get_root_id());
}
}
......@@ -483,5 +483,4 @@ mod tests {
.expect("friends field must be an array of String")
);
}
}
......@@ -630,5 +630,4 @@ mod tests {
panic!();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment