-
Notifications
You must be signed in to change notification settings - Fork 235
Methods to read into a buffer should take an uninitialized buffer #288
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
Comments
i am not sure i understand the benefits of this approach? it would seem to push a bunch of use of unsafe onto hal consumers, practically you can initialise an array once and reuse it anyway, and it appears you could achieve the equivalent by transmuting a |
I agree with @ryankurte here. |
@ryankurte I might be misunderstanding you, but you cannot transmute an uninit array to an initialized array. It will result in undefined behavior and the compiler will do weird things. The point of returning the initialized array would mean that users wouldn't have to use unsafe. |
Absence of But most importantly I can reuse one array for multiple write. How I can do this if Just create other |
I do not think the Thus, I believe, the right place for such an API would be the HAL crates themselves. I would assume that anyone who is optimizing to this extend is most likely not using generic drivers anyway - instead they would want to interact with the hardware as directly as possible, to have full control over the performance of the code. If it does turn out to be a common requirement, I think introducing a separate, special |
Methods like
blocking::i2c::Read::read
should take&mut [MaybeUninit<u8>]
instead of&mut [u8]
to allow for uninitialized buffers to be used.For example:
should become
Since slices of maybe uninit can only be converted to slices of normal types through unsafe, the methods should return the initiated slice.
Issues raised in #286 apply, namely that the returned slice may refer to a subslice of the input buffer. If that's a safety issue, the traits should be made unsafe to enforce that invariant.
The text was updated successfully, but these errors were encountered: