SQ in silver chrome letters, a lab's gear stacked against the S: a rack, two oscilloscopes, pizza boxes and a six-pack. Strange Query Lab

CARDIAC › rust-cardiac › Message codes › RCE0038

RCE0038error

An iterator the compiler doesn't have.

error[RCE0038]: iterators other than ranges aren't supported: index the array in a `for i in 0..N` loop ({why})

An iterator, or an iterator adapter, the compiler doesn't turn into a loop.

The compiler writes many of the iterators rustc leaves as calls as the loops they stand for: ranges, for x in array, .iter() and some of its methods. Others, and chains of adapters, it doesn't have yet.

Index the array in a for loop over a range.

// refused
let total: i16 = t.iter().map(|v| v * 2).sum();
// compiles
let mut total = 0;
for i in 0..t.len() {
    total += t[i] * 2;
}

In a terminal: cargo cardiac help RCE0038.