Skip to content
Snippets Groups Projects
Commit 9a9679ca authored by dvermd's avatar dvermd
Browse files

[fix] common-doc: #134 remove unwrap and deny its use

parent 65d45b7f
No related branches found
No related tags found
1 merge request!244Resolve "Reliability: remove all "unwrap()" and deny their use"
...@@ -161,13 +161,11 @@ impl Blockstamp { ...@@ -161,13 +161,11 @@ impl Blockstamp {
pub fn from_string(src: &str) -> Result<Blockstamp, BlockstampParseError> { pub fn from_string(src: &str) -> Result<Blockstamp, BlockstampParseError> {
let mut split = src.split('-'); let mut split = src.split('-');
if split.clone().count() != 2 { match (split.next(), split.next(), split.next()) {
Err(BlockstampParseError::InvalidFormat()) (Some(id), Some(hash), None) => {
} else { let hash = Hash::from_hex(hash)?;
let id = split.next().unwrap().parse::<u32>();
let hash = Hash::from_hex(split.next().unwrap())?;
if let Ok(id) = id { if let Ok(id) = id.parse::<u32>() {
Ok(Blockstamp { Ok(Blockstamp {
id: BlockNumber(id), id: BlockNumber(id),
hash: BlockHash(hash), hash: BlockHash(hash),
...@@ -176,5 +174,7 @@ impl Blockstamp { ...@@ -176,5 +174,7 @@ impl Blockstamp {
Err(BlockstampParseError::InvalidBlockNumber()) Err(BlockstampParseError::InvalidBlockNumber())
} }
} }
_ => Err(BlockstampParseError::InvalidFormat()),
}
} }
} }
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
//! Provide common tools for DUBP. //! Provide common tools for DUBP.
#![deny( #![deny(
clippy::option_unwrap_used,
clippy::result_unwrap_used,
missing_debug_implementations, missing_debug_implementations,
missing_copy_implementations, missing_copy_implementations,
trivial_casts, trivial_casts,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment