I'm learning to write iterators in Rust but am hitting an "expected colon" issue where I would not expect a colon to even make sense. Maybe it has to do with lifetimes? References? I tried making a regular function that returns the same data in the same way and it worked (or at least got past this error message) so it appears to be special to the Iterator
trait... but I can't work out why.
struct LogEntry;
pub struct LogIter<'a> {
index0: bool,
first: LogEntry,
iter: ::std::slice::Iter<'a, LogEntry>,
}
impl<'a> Iterator for LogIter<'a> {
type Item = &'a LogEntry;
fn next(&mut self) -> Option<Self::Item> {
self.index0 = false;
match self.index0 {
true => Some(&'a self.first),
false => self.iter.next(),
}
}
}
It is meant to return first
and then iterate normally but I cannot figure out why or how I could possibly fit a colon in here.
error: expected `:`, found keyword `self`
--> src/lib.rs:14:30
|
14 | true => Some(&'a self.first),
| ^^^^ expected `:`