iterator
C programmers usually traverse data with indexes or pointers:
for (size_t i = 0; i < len; i++) {
sum += data[i];
}
Or:
for (uint8_t *p = buf; p < buf + len; p++) {
*p ^= key;
}
Rust can write loops too, but the more common model is the iterator. It is not just fancy syntax. It turns traversal into a value that can be passed, composed, and consumed.
let sum: u32 = data.iter().map(|b| *b as u32).sum();
This article focuses on the engineering model C programmers need: how to move from index loops to iterators, when traversal borrows, when it mutably borrows, and when it consumes a container.
Read More