-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support backing via [u8; N]
#6
Comments
Using
Despite these points, it's the better and more flexible solution going forward. So if you have good ideas, I'd be happy to hear them.
|
Ack. That seems reasonable to me (in the case you're not specifying an explicit backing type).
Maybe it's best to just leave that up to the user, whether they want to make it
I suppose the same could be asked of the current implementation? I could be wrong, but doesn't the current impl already assume native endian ordering when it comes to defining accessors to fields? This is a reasonable question to ask, but also, something that I don't think is strictly required in a hypothetical "v1" implementation of this feature. Though, if we're spitballing: I could imagine specifying it as an additional param to
Well, yes, it might be a bit more complicated since you might have fields that span across multiple bytes, but you should be able to write the code in such a way that each accessor function uses the same generated code "template", with the only difference being the specific "bounds" of the inner array the code accesses, along with two "start" and "end" bounds corresponding to the byte index in the left-most and right-most byte of that subslice. If need be, we could collab on the specifics here, but I don't think it'll be too hard.
Totally reasonable! The fun with open source is how folks end up using your lib in ways you didn't even forsee, and, well, here we are :)
Haha, yes, math is hard, oops 😅 |
Ok, good points. So 1B alignment, no
Thanks, I might come back to that 😅
To reduce duplicate code, other proc_macro libraries consist of two crates, one for generating the code and another with functions called by the generated code. This might also be useful if we want to have our own traits/types... Then we could implement a function like: fn set_bits<const N: usize, const M: usize>(
dst: &mut [u8; N],
dst_offset: usize,
src: &[u8; M],
src_offset: usize,
len: usize); And in the generated code, we just use it. Oh, and I forgot one thing: custom types and enums. Currently, we support types that are convertible to the bitfield's integer type. This would have to change to |
Yeah, sounds good! Thanks for looking into this!
As a suggestion: why not make the required conversion function dependent on the field size, rather than the size of the backing bitfield-struct? Even in the current implementation, it does seem a bit weird that in order to use a custom type with, say, a |
I've created pr #7 for this. |
First off: thanks for this crate!
The syntax is clean and intuitive, and is a lot easier to use than the other bitfield crates i've seen on crates.io.
Right now, the generated bitfield can only be backed by various integer types, which has 3 pretty major limitations:
sizeof(u128)
repr(packed)
fields (orrepr(C)
fields + something like thezerocopy
crate)A clean solution to overcoming all 3 of these limitations would be to support backing the generated bitfield using a
[u8; N]
array.Happy to brainstorm specifics of syntax / featureset, but I was thinking it could look something like:
Cheers!
The text was updated successfully, but these errors were encountered: