Answers for "rust for vs for_each"

0

rust for vs for_each

This is equivalent to using a for loop on the iterator,
although break and continue are not possible from a closure.

It's generally more idiomatic to use a for loop,
but for_each may be more legible when processing
items at the end of longer iterator chains.

In some cases for_each may also be faster than a loop,
because it will use internal iteration on adaptors like Chain.
Posted by: Guest on August-22-2020

Browse Popular Code Answers by Language