hecatia-elegua / bilge

Use bitsized types as if they were a feature of rust.
Apache License 2.0
171 stars 17 forks source link

Support fallbacks with values #44

Closed pickx closed 1 year ago

pickx commented 1 year ago

Fixes #43.

shared.rs was getting a bit cluttered so I split it into util.rs,fallback.rs and variant_value_assigner.rs. Is that okay? Would you like me to make a separate PR first, containing just the restructuring?

As usual, any style/implementation suggestions are welcome. Feel free to correct anything that looks weird.

hecatia-elegua commented 1 year ago

This is super nice, Single would be cool to have in rust std. Itertools has something like this too (but yours is better here). I've just done a quick skim rn and yeah, that's how I would split shared.rs as well, by introducing new lower modules. The new example can instead be a test. bitsize_from_type_token should be moved to shared, so we don't depend upwards/circular.

pickx commented 1 year ago

Single would be cool to have in rust std. Itertools has something like this too (but yours is better here).

right? I find that I have a use for something like this pretty often. the API of Itertools's implementation is a little unfortunate and I gave up on it. actually scratch that, I was just being stubborn.

The new example can instead be a test.

sure. I used the example as a basis for some basic tests. I also kept a more minimal version of the example because I think it's instructive to show the difference between the two forms of #[fallback].

hecatia-elegua commented 1 year ago

merging tomorrow