rust-ux / uX

Non standard integer types like `u7`, `u9`, `u10`, `u63`, `i7`, `i9`
Apache License 2.0
119 stars 37 forks source link

idea: bit packing design #77

Closed dzmitry-lahoda closed 2 months ago

dzmitry-lahoda commented 2 months ago

https://ziglang.org/documentation/master/#toc-packed-struct

so should i14 to occupy 14 bit in stuct or 16? zig seems may vary it. if rust would have arbitrary bit integers it can be next

struct iX<const value_bits, const memory_bits> where value_bits <= memory_bits  ()

so one can tell exactly how much each stuct is in mem.

simplification would be just follow zig rules, so second constant is not needed.

also it should consider attrs from https://doc.rust-lang.org/reference/type-layout.html

or use like https://github.com/hashmismatch/packed_struct.rs

Reason one may have arbitrary bit primitives if he wants to use part of bits for other primitive or flags.

So proper design of such integer should make sure it is compatible with alignment and bit level packing

dzmitry-lahoda commented 2 months ago

after searching rust-lang issues, found by jumping https://github.com/danlehmann/bitfield