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

Express Leaf and Parent types in the type system

yoshuawuyts opened this issue · comments

commented

We're having trouble that PartialNode.data is of Option<Vec<u8>>, so when we move it out of the Option, we get a move error.

Instead by encoding this in the type system, we no longer require .as_ref() + .unwrap() to access the data. This should provide an API that is easier to reason about, and potentially more safe.

commented

Done!

commented

Oh actually, we haven't lol

commented

We should call the enum NodeKind, similar to how ErrorKind is a thing in stdlib.

commented

Also fun pointing out that all even numbers in the tree are leaves, where all uneven numbers are parents. Good to know (:

@yoshuawuyts

I'd love to help here! I'm definitely still new to Rust, so before I dive in, I want to make sure I understand what the desired outcome is, and if you can help point me in the right direction.

that PartialNode.data is of Option<Vec<u8>>

This is true of DefaultNode.data, too, right?

What is the idiomatic way in Rust to express this at the type level? You mention making a NodeKind enum, can you give me a concrete idea of what that would look like? Can you point to some good example in the Rust ecosystem of a similar structure that I can base my changes on?

Thanks!

I'm going to flail around at an implementation where I replace data: Option<Vec<u8>> with data: NodeKind. I am pretty confident that my first attempt will be off, but working from something is easier than working from nothing!

commented

Fixed in #18. Thanks! 🎉