All,
I need to create a function that takes the length of an array (usize) and if it is not evenly divisible by 16, round it up to the next multiple of 16. This requires being able to evaluate the size of an array at compile time and more importantly being able to use the output of this function (usize) as the size of a new array. All of the information in theory is available at compile time so I would imagine there is a way to do this. Here is a basic example with rust nightly 1.47
#![feature(const_generics, const_fn)]
const fn return_size(input: usize) -> usize {
let mut new_size: usize = 0;
if (input % 16 != 0) {
new_size = input + (16 - input % 16);
new_size
}
else {
input
}
}
fn main() {
let this_array: [f32; 2] = [0.0, 0.0];
//let resized_array: [f32; return_size(this_array.len())] = [fill with zereos];
}