These lines of code are repeated many times throughout my code, but each time the array being read is of a different numeric type and different size:
let mut section_offsets = [0u32; 15];
for x in section_offsets.iter_mut() {
*x = rdr.read_u32::<BE>()?;
}
What I want is a function read_array which takes in the size and numeric type of the array to be read (as well as rdr: &mut impl Read), reads the array and returns an io::Result of the array. Is there any way of doing this without having to write loads of functions for each array type?
I got as far as using const generics to define the size of the array but couldn't figure out how to do it using generic types.