docs

您正在閱讀 v0.1.0 的文件。Nabi 0.1.0 已停止支援。 最新版本:v0.1.3 →

本頁尚未翻譯,以下為英文原文。

#E0068: value cannot be iterated

for iterates an integer range with a start (0..n, 0..), an array, or a type that implements IntoIterator or Iterator (whose next returns T | none); try for iterates a TryIterator. Iterate one of those, or call the method that gives an iterator.

nabi
struct Bag { n: i32; }

let b = Bag { n: 3 };
for x in b {
    println(f"{x}");
}
error[E0068]: cannot iterate over a value of type `Bag` - `for` needs an integer range, an array, an `IntoIterator` / `Iterator` impl, or a `TryIterator` (`try for`)
  --> main.nabi:4:1
   |
 4 | for x in b {
   | ^^^^^^^^^^^^

Iterate a range, a collection or an iterator:

nabi
struct Bag { n: i32; }

let b = Bag { n: 3 };
for x in 0..b.n {
    println(f"{x}");
}
0
1
2

Related: E0069 trait bound not satisfied

Found a mistake? Edit this page on GitHub. Last updated