-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Working with arrays #96
Comments
I think I would need to insist on seeing a benchmark and/or generated code
to justify this. It seems like if you have an array, then the optimizer
should see through that and elide bounds checks, no?
…On Sep 8, 2017 2:46 AM, "Martin Habovštiak" ***@***.***> wrote:
Current implementation uses &[u8] for reading and &mut [u8] for writing,
which panics if lengths are invalid. I suggest to implement alternative
functions like read_arr_u16(but: &[u8; 2]) (name subject to bike
shedding), that would take reference to array.
This would come handy in combination with constant generics, where code
could guarantee absence of panics (due to programmer error) and elision of
(unnecessary) checks.
Once constant generics are in Rust, the old (&[u8]) versions could be
implemented using new ones. I guess this could be done with macros.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#96>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAb34oV4o5SnV4cSA-SNRjO0vRlCICXTks5sgOLKgaJpZM4PQwsX>
.
|
If the function inlines, then yes. Seems like I didn't make myself clear that I was referring to statically proving that the code can't panic. I prefer discovering bugs during compilation. |
Yeah, I'm not on board with that. I don't value type safety above everything else. In this case, you're talking about doubling the size of the current API. When const generics lands, we can revisit this. |
OK, thanks for reply! |
Current implementation uses
&[u8]
for reading and&mut [u8]
for writing, which panics if lengths are invalid. I suggest to implement alternative functions likeread_arr_u16(but: &[u8; 2])
(name subject to bike shedding), that would take reference to array.This would come handy in combination with constant generics, where code could guarantee absence of panics (due to programmer error) and elision of (unnecessary) checks.
Once constant generics are in Rust, the old (
&[u8]
) versions could be implemented using new ones. I guess this could be done with macros.The text was updated successfully, but these errors were encountered: