datrs / merkle-tree-stream

A stream that generates a merkle tree based on the incoming data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consider using associated types instead of type parameters for HashMethods

yoshuawuyts opened this issue · comments

commented

Right now the API for HashMethods is impl HashMethods<Node> for S {}, but instead we could do:

impl HashMethods for S {
  type Node = Node;
}

This will make our API a bit more rusty / ergonomic.

commented

Hash should also be an associated type.

impl HashMethods for S {
  type Node = Node;
  type Hash = Hash;
}

Which will allow us to call parent and leaf methods with -> Self::Hash. This should make the whole pipeline typed, which is a win.

The only open question is how this would interact with DefaultNode, as it would now become generic over the Hash type. Maybe defaulting to Vec<u8> would make sense for it, keeping the API as is?