But this requires the const_generics and const_evaluatable_checked features and I don't want to be relying on anything that triggers the incomplete_features lint. min_const_generics is in beta though, so I'm happy to use that.
Are there any workarounds on stable Rust where I can take a fixed-length array and return a new array which is 1/4 the length?
I tried adding another layer of indirection using traits and an associated const, but that didn't get me very far.
Example using associated constants
trait MultiplyBy4 {
const VALUE: usize;
type Array;
}
impl<const N: usize> MultiplyBy4 for [f32; N]
{
const VALUE: usize = N*4;
type Array = [f32; Self::VALUE];
}
Fails to compile with
error: generic `Self` types are currently not permitted in anonymous constants
--> src/lib.rs:16:24
|
16 | type Array = [f32; Self::VALUE];
| ^^^^^^^^^^^
|
note: not a concrete type
--> src/lib.rs:13:38
|
13 | impl<const N: usize> MultiplyBy4 for [f32; N]
| ^^^^^^^^
Variations on this seem to fail with similar errors.
(or with [[f32; N]; 4] instead of [[f32; 4]; N] if that makes more sense) do the job?
(That won't work on stable because even min_const_generics has not hit stable yet. But if you're willing to use beta, or nightly without feature gates, it should be okay.)
The previous step returns a [f32; 32] that this step needs to "condense" into a [f32; 4], but I wanted to make this operation work with more than just [f32; 32] because it'll pop up elsewhere.
I guess I could make the previous step return a multidimensional array instead. We're already using FFI to populate the array, so an extra transmute() won't cause much harm.