diff --git a/firewood/src/merkle.rs b/firewood/src/merkle.rs index d5a15ee31..b02b51b0a 100644 --- a/firewood/src/merkle.rs +++ b/firewood/src/merkle.rs @@ -116,7 +116,7 @@ where let children: [Option>; BranchNode::MAX_CHILDREN] = Default::default(); EncodedNode { partial_path: n.partial_path.clone(), - children: Box::new(children), + children, value: n.value.clone().into(), phantom: PhantomData, } @@ -171,7 +171,7 @@ where partial_path: encoded.partial_path, children: [None; BranchNode::MAX_CHILDREN], value: encoded.value, - children_encoded: *encoded.children, + children_encoded: encoded.children, } .into(), )) diff --git a/firewood/src/merkle/node.rs b/firewood/src/merkle/node.rs index df5871005..2bf5636fb 100644 --- a/firewood/src/merkle/node.rs +++ b/firewood/src/merkle/node.rs @@ -463,21 +463,27 @@ impl Storable for Node { /// Contains the fields that we include in a node's hash. /// If this is a leaf node, `children` is empty and `value` is Some. /// If this is a branch node, `children` is non-empty. -#[derive(Debug)] +#[derive(Debug, Eq)] pub struct EncodedNode { pub(crate) partial_path: Path, /// If a child is None, it doesn't exist. /// If it's Some, it's the value or value hash of the child. - pub(crate) children: Box<[Option>; BranchNode::MAX_CHILDREN]>, + pub(crate) children: [Option>; BranchNode::MAX_CHILDREN], pub(crate) value: Option>, pub(crate) phantom: PhantomData, } +// driving this adds an unnecessary bound, T: PartialEq +// PhantomData is PartialEq for all T impl PartialEq for EncodedNode { fn eq(&self, other: &Self) -> bool { - self.partial_path == other.partial_path - && self.children == other.children - && self.value == other.value + let Self { + partial_path, + children, + value, + phantom: _, + } = self; + partial_path == &other.partial_path && children == &other.children && value == &other.value } } @@ -536,7 +542,7 @@ impl<'de> Deserialize<'de> for EncodedNode { Ok(Self { partial_path: path, - children: children.into(), + children, value, phantom: PhantomData, }) @@ -607,7 +613,7 @@ impl<'de> Deserialize<'de> for EncodedNode { let children: [Option>; BranchNode::MAX_CHILDREN] = Default::default(); Ok(Self { partial_path: path, - children: children.into(), + children, value: Some(value), phantom: PhantomData, }) @@ -629,7 +635,7 @@ impl<'de> Deserialize<'de> for EncodedNode { Ok(Self { partial_path: path, - children: children.into(), + children, value, phantom: PhantomData, })