我是 Rust 新手,我正在尝试找出在 Rust 中执行以下操作的最佳方法是什么:
struct ThingIterator {
current: String,
stop: String,
}
impl Iterator for ThingIterator {
type Item = &str;
fn next(&mut self) -> Option<&str> {
if self.current == self.stop {
return None;
}
// For testing
self.current = self.stop;
Some(&self.current)
}
}
fn main() {
let pi = ThingIterator {
current: String::from("Ask"),
stop: String::from("Zoo"),
};
println!("Number of things={}", pi.count());
}
Run Code Online (Sandbox Code Playgroud)
我的错误是:
error[E0106]: missing lifetime specifier
--> src/main.rs:7:17
|
7 | type Item = &str;
| ^ expected …Run Code Online (Sandbox Code Playgroud) rust ×1