How do I cope with lazy iterators?

后端 未结 3 1903
故里飘歌
故里飘歌 2020-12-10 21:58

I\'m trying to sort an array with a map() over an iterator.

struct A {
    b: Vec,
}

#[derive(PartialEq, Eq, PartialOrd, Ord)]
struct          


        
3条回答
  •  再見小時候
    2020-12-10 22:31

    I use for_each. According to the doc:

    It 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.

提交回复
热议问题