A skeleton code for Iterator in Rust

For record, I wrote down the same code.

Consuming Iterator

https://gist.github.com/hyunsik/d4a8743bf6b5bf1ea7a4

Iterator that does not consume items


pub struct TaskSetRefIterator<'a>
{
….
}
impl<'a> Iterator for TaskSetRefIterator<'a> {
type Item = &'a Task;
fn next(&mut self) -> Option<&'a Task> {
None
}
}
impl<'a> IntoIterator for &'a TaskSet {
type Item = &'a Task;
type IntoIter = TaskSetRefIterator<'a>;
fn into_iter(self) -> Self::IntoIter {
TaskSetRefIterator { … }
}
}

view raw

task2.rs

hosted with ❤ by GitHub