You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if read_NNN_into() would support types that are byte-compatible with integers, such as in this case Wrapping<u16>.
(I'm relatively inexperienced with Rust so maybe there's some existing way to do this that I'm missing, without copying the buffer and without unsafe code!)
The text was updated successfully, but these errors were encountered:
I don't think it makes a lot of sense for byteorder to support this on its own. The simplest way would be to add read_wrapping_u16_into APIs (along with the other various integer types), but that bloats the API considerably. We could modify the existing read_u16_into APIs to take a generic parameter, and add traits for performing zero-cost conversions between integer types. But this is a lot of infrastructure, and would ultimately require a byteorder 2.0 release because making APIs generic tends to lead to breaking changes in practice.
Longer term, I think the answer to this will be better support from Rust itself. The "safer transmute" RFC is a good starting point to see what folks are up to in this space currently. For a more immediate answer, your options are to either use unsafe, or use one of the crates that provide the "safer transmute" functionality as a library. For example, bytemuck or zerocopy. Those should let you write the code you want without unsafe.
Hi! 👋 My use case is that I'd like to read a data file into a buffer of
Wrapping<u16>
. Here's an example program, that doesn't compile:It would be nice if
read_NNN_into()
would support types that are byte-compatible with integers, such as in this caseWrapping<u16>
.(I'm relatively inexperienced with Rust so maybe there's some existing way to do this that I'm missing, without copying the buffer and without unsafe code!)
The text was updated successfully, but these errors were encountered: