How do I cope with lazy iterators?

后端 未结 3 1901
故里飘歌
故里飘歌 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:49

    As the book you linked to says:

    If you are trying to execute a closure on an iterator for its side effects, use for instead.

    That way it works, and it's much clearer to anyone reading the code. You should use map when you want to transform a vector to a different one.

提交回复
热议问题