Typing on array size
⚓ Rust 📅 2026-03-29 👤 surdeus 👁️ 9I have an algorithm which utilises arrays of u32. It would be good to parameterise this size. Since the algorithm works with any size of array as long as the sizes in one operation are all identical.
So for the function
fn do_something(src: [u32;5], dst: [u32;5], weight: [u32;5])
it would be good to reuse the code as
fn do_something(src: [u32;7], dst: [u32;7], weight: [u32;7])
and ensure that all the sizes are the same.
I understand that this would need to be a compile time choice rather than a runtime choice.
Is there a way to do this? A link to the docs would be good, examples even better.
thanks in advance
Phill
4 posts - 3 participants
🏷️ Rust_feed