Skip to content
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

le and be #9

Closed
hecatia-elegua opened this issue Jan 17, 2023 · 7 comments
Closed

le and be #9

hecatia-elegua opened this issue Jan 17, 2023 · 7 comments

Comments

@hecatia-elegua
Copy link
Collaborator

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: Robbepop/modular-bitfield#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.

@hecatia-elegua
Copy link
Collaborator Author

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.

@danlehmann
Copy link
Owner

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?

@hecatia-elegua
Copy link
Collaborator Author

I noticed that as well while implementing and proceeded to do multiples of 8.

@hecatia-elegua
Copy link
Collaborator Author

This is still lying around somewhere, will try to add this soon.

@hecatia-elegua
Copy link
Collaborator Author

"soon"

@danlehmann
Copy link
Owner

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

@danlehmann
Copy link
Owner

#17
#16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants