Skip to content

Commit 4d3be8e

Browse files
committed
chore(clippy): fix all target clippy warning
1 parent 771d75b commit 4d3be8e

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

bindings/python/src/codec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ impl<'py> FromPyObject<'py> for PyCodecFormat {
2323
)),
2424
}
2525
} else {
26-
return Err(PyValueError::new_err(
26+
Err(PyValueError::new_err(
2727
"Unable to convert into proper encoding.",
28-
));
28+
))
2929
}
3030
}
3131
}
@@ -76,7 +76,7 @@ where
7676
serde_json::from_slice(data)
7777
}
7878

79-
pub fn from_str(data: &'de str) -> Result<Self, serde_json::Error> {
79+
pub fn from_str_utf8(data: &'de str) -> Result<Self, serde_json::Error> {
8080
serde_json::from_str(data)
8181
}
8282

@@ -122,7 +122,7 @@ mod hex_serde {
122122
where
123123
S: Serializer,
124124
{
125-
serializer.serialize_str(faster_hex::hex_string(&bytes).as_str())
125+
serializer.serialize_str(faster_hex::hex_string(bytes).as_str())
126126
}
127127

128128
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>

bindings/python/src/crypto.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ macro_rules! py_digest {
5454
}
5555
}
5656

57+
impl Default for $name {
58+
fn default() -> Self {
59+
Self::new()
60+
}
61+
}
62+
5763
impl PyDigest for $name {
5864
type Inner = $digest;
5965

bindings/python/src/tree.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ macro_rules! py_mrkle_node {
118118
tree: &Tree<$name, usize>,
119119
children: Vec<NodeIndex<usize>>,
120120
) -> Result<Self, NodeError> {
121-
Ok(<$name>::internal(tree, children)?)
121+
<$name>::internal(tree, children)
122122
}
123123
}
124124

@@ -611,7 +611,7 @@ macro_rules! py_mrkle_tree {
611611
let buf = JsonCodec::<&[u8], $digest>::new(
612612
self.inner
613613
.start()
614-
.and_then(|root| self.from_node(root, &mut HashMap::new()))
614+
.and_then(|root| self.visit_node(root, &mut HashMap::new()))
615615
.ok_or_else(|| SerdeError::new_err("JSON could not be serialized."))?,
616616
);
617617

@@ -700,7 +700,7 @@ macro_rules! py_mrkle_tree {
700700
let json_codec = if let Ok(bytes) = data.extract::<&[u8]>() {
701701
JsonCodec::<Box<[u8]>, $digest>::from_slice(bytes)
702702
} else if let Ok(string) = data.extract::<String>() {
703-
JsonCodec::<Box<[u8]>, $digest>::from_str(string.as_str())
703+
JsonCodec::<Box<[u8]>, $digest>::from_str_utf8(string.as_str())
704704
} else {
705705
return Err(PyTypeError::new_err(
706706
"Expected bytes or string for JSON deserialization",
@@ -853,8 +853,8 @@ macro_rules! py_mrkle_tree {
853853
self.inner.iter()
854854
}
855855

856-
fn build_tree_from_json<'py>(
857-
py: Python<'py>,
856+
fn build_tree_from_json(
857+
py: Python<'_>,
858858
node: MerkleTreeJson<Box<[u8]>>,
859859
tree: &mut Tree<$node, usize>,
860860
) -> PyResult<NodeIndex<usize>> {
@@ -897,7 +897,7 @@ macro_rules! py_mrkle_tree {
897897
<$node>::internal(tree, children).map_err(|e| PyNodeError::new_err(format!("{e}")))
898898
}
899899

900-
fn from_node(
900+
fn visit_node(
901901
&self,
902902
index: NodeIndex<usize>,
903903
visited: &mut HashMap<usize, ()>,
@@ -920,7 +920,7 @@ macro_rules! py_mrkle_tree {
920920
// Parent node
921921
let children: Vec<_> = children_indices
922922
.iter()
923-
.filter_map(|&child_idx| self.from_node(child_idx, visited))
923+
.filter_map(|&child_idx| self.visit_node(child_idx, visited))
924924
.collect();
925925

926926
Some(MerkleTreeJson::Parent { hash, children })
@@ -1046,7 +1046,7 @@ fn traverse_dict_depth<N: PyMrkleNode<D, usize>, D: Digest>(
10461046
tree.set_root(Some(root));
10471047
Ok(())
10481048
} else {
1049-
Err(PyValueError::new_err(format!(
1049+
Err(PyValueError::new_err(String::from(
10501050
"Invalid value type for expected dict or bytes",
10511051
)))
10521052
}
@@ -1076,13 +1076,13 @@ fn process_traversal<N: PyMrkleNode<D, usize>, D: Digest>(
10761076
return Ok(node_id);
10771077
}
10781078

1079-
if let Ok(child) = extract_to_bytes(&value) {
1079+
if let Ok(child) = extract_to_bytes(value) {
10801080
let leaf = N::leaf(child);
10811081
let index = tree.push(leaf);
10821082
return Ok(index);
10831083
}
10841084

1085-
Err(PyValueError::new_err(format!(
1085+
Err(PyValueError::new_err(String::from(
10861086
"Invalid value type for: expected dict or bytes",
10871087
)))
10881088
}

0 commit comments

Comments
 (0)