BlockstreamResearch / rust-simplicity

Creative Commons Zero v1.0 Universal
58 stars 12 forks source link

u2 type is not exported #219

Closed apoelstra closed 4 months ago

apoelstra commented 4 months ago

BitIter::read_u2 is unusable because its return type is not exported

uncomputable commented 4 months ago

I see. The caller cannot match the returned enum u2 and there are no From<u2> implementations.

uncomputable commented 4 months ago

I'm not 100% convinced of the usefulness of read_u2 as a public method. We use it because the Simplicity bit encoding happens to work in terms of 2 bits sometimes. Downstream users can use read_u2 to decode their own custom bit encoding. Is that an intended use case of the library? Making the bit iterator interface private would turn the iterator into an opaque type used for Simplicity parsing only, though.

apoelstra commented 4 months ago

Is that an intended use case of the library?

It's what I'm trying to do, yes.

I think if Simplicity is going to have a bit encoding it should have "general-purpose" bit decoding methods. You need these to manipulate Simplicity encodings directly, which is sometimes needed because the library doesn't let you work with many kinds of malformed/incorrectly typed/etc objects. Its Value handling is also really inefficient.