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

Optional bytemuck support #83

Closed
edgarogh opened this issue Jul 22, 2024 · 1 comment · Fixed by #99
Closed

Optional bytemuck support #83

edgarogh opened this issue Jul 22, 2024 · 1 comment · Fixed by #99

Comments

@edgarogh
Copy link

bytemuck allows safe transmuting of simple types with no uninhabited values. I would be really useful if hybrid-array implemented it the same way bytemuck implements it on native constant-sized arrays. Obviously, the dependency would be optional.

How ?

This is the impl for the standard generic array, it should be trivial to adapt:

unsafe impl<T, const N: usize> Pod for [T; N] where T: Pod {}

source: https://github.com/Lokathor/bytemuck/blob/005ee3254fdfa63d67d024cfc598319331dab0cb/src/pod.rs#L87

Why ?

  • bytemuck is quite popular (3.5M downloads/month, 600+ GH stars)
  • Implementing it would instantly make hybrid arrays of int/bytes/etc. safely transmutable with other kinds of arrays at no cost, including non-standard ones

Why not ?

  • It adds a dependency
  • It's always possible to get access to the underlying &[T; N]/&mut [T; N] (and vice-versa) using normal hybrid_array::Array methods and give these to bytemuck instead. It adds one "level" of conversion, which is acceptable.
@tarcieri
Copy link
Member

I'd be okay with adding it as an optional dependency

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

Successfully merging a pull request may close this issue.

2 participants