Skip to content

Commit

Permalink
Use let/else instead of if/let/else
Browse files Browse the repository at this point in the history
Per review comments
  • Loading branch information
rkuris committed Nov 14, 2023
1 parent 936d0b5 commit 94a4244
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions firewood/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1323,33 +1323,32 @@ impl<'a, S: shale::ShaleStore<node::Node> + Send + Sync> Stream for MerkleKeyVal
match last_node.inner() {
NodeType::Branch(branch) => {
// previously rendered the value from a branch node, so walk down to the first available child
if let Some(child_position) =
let Some(child_position) =
branch.children.iter().position(|&addr| addr.is_some())
{
let child_address = branch.children[child_position].unwrap();
else {
// Branch node with no children?
return Poll::Ready(Some(Err(api::Error::InternalError(Box::new(
MerkleError::ParentLeafBranch,
)))));
};
let child_address = branch.children[child_position].unwrap();

parents.push((last_node, child_position as u8)); // remember where we walked down from
parents.push((last_node, child_position as u8)); // remember where we walked down from

let current_node = self
.merkle
.get_node(child_address)
.map_err(|e| api::Error::InternalError(e.into()))?;
let current_node = self
.merkle
.get_node(child_address)
.map_err(|e| api::Error::InternalError(e.into()))?;

let found_key = key_from_parents(&parents);
let found_key = key_from_parents(&parents);

self.key_state = IteratorState::Iterating {
// continue iterating from here
last_node: current_node,
parents,
};
self.key_state = IteratorState::Iterating {
// continue iterating from here
last_node: current_node,
parents,
};

found_key
} else {
// Branch node with no children?
return Poll::Ready(Some(Err(api::Error::InternalError(Box::new(
MerkleError::ParentLeafBranch,
)))));
}
found_key
}
NodeType::Leaf(leaf) => {
let mut next = parents.pop();
Expand Down

0 comments on commit 94a4244

Please sign in to comment.