数组迭代
for 语句支持对数组进行迭代(但不支持元组)。
fn main() { let primes = [2, 3, 5, 7, 11, 13, 17, 19]; for prime in primes { for i in 2..prime { assert_ne!(prime % i, 0); } } }
此功能使用了 IntoIterator trait,但我们还没有讲到它。
The assert_ne! macro is new here. There are also assert_eq! and assert! macros. These are always checked, while debug-only variants like debug_assert! compile to nothing in release builds.