pub struct Iter<'a, T> {
next: Option<&'a Node<T>>,
}
impl<'a, T> List<T> {
pub fn iter(&'a self) -> Iter<'a, T> {
Iter { next: self.head.map(|node| &'a node) }
}
}
impl<'a, T> Iterator for Iter<'a, T> {
type Item = &'a T;
fn next(&'a mut self) -> Option<Self::Item> {
self.next.map(|node| {
self.next = node.next.map(|node| &'a node);
&'a node.elem
})
}
}
error: expected `:`, found `node`
--> src/second.rs:54:47
|
54 | Iter { next: self.head.map(|node| &'a node) }
| ---- while parsing this struct ^^^^ expected `:`
error: expected `:`, found `node`
--> src/second.rs:62:50
|
62 | self.next = node.next.map(|node| &'a node);
| ^^^^ expected `:`
error: expected `:`, found `node`
--> src/second.rs:54:47
|
54 | Iter { next: self.head.map(|node| &'a node) }
| ---- while parsing this struct ^^^^ expected `:`
error: expected `:`, found `node`
--> src/second.rs:62:50
|
62 | self.next = node.next.map(|node| &'a node);
| ^^^^ expected `:`
error[E0308]: method not compatible with trait
--> src/second.rs:60:5
|
60 | fn next(&'a mut self) -> Option<Self::Item> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected type `fn(&mut second::Iter<'a, T>) -> std::option::Option<&T>`
found type `fn(&'a mut second::Iter<'a, T>) -> std::option::Option<&T>`
note: the anonymous lifetime #1 defined on the method body at 60:5...
--> src/second.rs:60:5
|
60 | / fn next(&'a mut self) -> Option<Self::Item> {
61 | | self.next.map(|node| {
62 | | self.next = node.next.map(|node| &'a node);
63 | | &'a node.elem
64 | | })
65 | | }
| |_____^
note: ...does not necessarily outlive the lifetime 'a as defined on the impl at 58:6
--> src/second.rs:58:6
|
58 | impl<'a, T> Iterator for Iter<'a, T> {
| ^^
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.
error: Could not compile `rusttest`.
warning: build failed, waiting for other jobs to finish...
error[E0308]: method not compatible with trait
--> src/second.rs:60:5
|
60 | fn next(&'a mut self) -> Option<Self::Item> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected type `fn(&mut second::Iter<'a, T>) -> std::option::Option<&T>`
found type `fn(&'a mut second::Iter<'a, T>) -> std::option::Option<&T>`
note: the anonymous lifetime #1 defined on the method body at 60:5...
--> src/second.rs:60:5
|
60 | / fn next(&'a mut self) -> Option<Self::Item> {
61 | | self.next.map(|node| {
62 | | self.next = node.next.map(|node| &'a node);
63 | | &'a node.elem
64 | | })
65 | | }
| |_____^
note: ...does not necessarily outlive the lifetime 'a as defined on the impl at 58:6
--> src/second.rs:58:6
|
58 | impl<'a, T> Iterator for Iter<'a, T> {
| ^^
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0308`.
error: Could not compile `rusttest`.
I don't understand the syntax errors. Commenting out the edition 2018 toggle doesn't help, either... What am I missing?