My code generally works with arrays of length 303, and I am overall happy to hard-code that number into my code. But for testing purposes, I would like to show the behaviour of some functions on smaller arrays. How do I implement the equivalent of the following pointwise function? Or is this impossible, and I'll just live with using slices and explicitly checking the sizes of each at runtime, instead of relying on the compiler to not let anything slip through?
pub fn recover<N>(
mut patch_resources: &[KCal; N],
patch_max_resources: &[KCal; N],
resource_recovery: f32,
accessible_resources: f32)
where
N: usize
{
for i in N {
if patch_resources[i] < patch_max_resources[i] {
let inaccessible = patch_max_resources[i] * (1. - accessible_resources) / accessible_resources;
let underlying_resources = patch_resources[i] + inaccessible;
patch_resources[i] += underlying_resources
* resource_recovery
* (1. - underlying_resources * accessible_resources/ patch_max_resources[i]);
}
assert!(patch_resources[i].is_normal());
}
}