Closed hecatia-elegua closed 1 year ago
I've tried implementing it but need to test it with bitfields first. The only difficulty is that we of course have some unfilled bits:
/// u24
pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self { //mem::size_of::<Self>() can't be used, would be 4
unsafe { mem::transmute(bytes) } //can't be used, we're 4 bytes wide, so we need to add a 0 byte
}
swap_bytes
works in a similar fashion.
Would such functions even be well-defined for everything? What does it mean for a u19 to be be vs le?
I can see how it makes sense in bitfield, but in arbitrary_int, should we limit this to multiples of 8?
I noticed that as well while implementing and proceeded to do multiples of 8.
This is still lying around somewhere, will try to add this soon.
"soon"
Working on this. Have swap_bytes and to_le_bytes (and ne and be) ready. from_ne_bytes is slightly more tricky, macro wise. Will upload a patch shortly
https://doc.rust-lang.org/src/core/num/uint_macros.rs.html to_le/to_be from_le/from_be
After reading issues like this: https://github.com/Robbepop/modular-bitfield/issues/46 I wondered how this could be handled by us. Adding these 4 functions would mirror the primitive numbers and they afaik just need to call their UnderlyingType's functions.