There's a similar pattern in rust:
fn loop(a: &[u8]) {
assert!(a.len >= 20);
for x in (0..20) {
let y = a[i];
//Do something with y
}
}
Adding the assert before the loop will remove the bounds checks happening on each iteration.