←back to thread

611 points LorenDB | 3 comments | | HN request time: 0s | source
1. nyanpasu64 ◴[] No.43910223[source]
The problem I've always had with unit type wrappers is you can't convert between a &[f32] and a &[Amplitude<f32>] like you can convert a single scalar value.
replies(2): >>43910307 #>>43912786 #
2. fvncc ◴[] No.43910307[source]
There are libraries that help with these conversions. See e.g.: https://docs.rs/bytemuck/latest/bytemuck/trait.TransparentWr...
3. conradludgate ◴[] No.43912786[source]
As long as the wrapper is marked as transparent, it's safe to transmute the wrappers.

If you don't want unsafe, you can make use of this safe derive: https://docs.rs/bytemuck/latest/bytemuck/trait.TransparentWr...