How to iterate over and filter an array?

后端 未结 3 1409
耶瑟儿~
耶瑟儿~ 2020-11-30 08:18

I\'m trying to write a program that involves filtering and folding over arrays. I\'ve been using The Rust Programming Language, first edition as a reference, but I don\'t un

3条回答
  •  迷失自我
    2020-11-30 09:13

    As Shepmaster and bluss said, you can check the documentation for the array type, which mentions:

    Arrays of sizes from 0 to 32 (inclusive) implement the following traits if the element type allows it:

    • IntoIterator (implemented for &[T; N] and &mut [T; N])

    As it says, this is only for references, and is reflected in its Item type: type Item = &'a T and type Item = &'a mut T.

提交回复
热议问题