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

Working with arrays #96

Closed
Kixunil opened this issue Sep 8, 2017 · 4 comments
Closed

Working with arrays #96

Kixunil opened this issue Sep 8, 2017 · 4 comments

Comments

@Kixunil
Copy link

Kixunil commented Sep 8, 2017

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.

@BurntSushi
Copy link
Owner

BurntSushi commented Sep 8, 2017 via email

@Kixunil
Copy link
Author

Kixunil commented Sep 9, 2017

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.

@BurntSushi
Copy link
Owner

BurntSushi commented Sep 10, 2017

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.

@Kixunil
Copy link
Author

Kixunil commented Sep 10, 2017

OK, thanks for reply!

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