steveklabnik / indexlist

indexlist: A doubly linked list, backed by a vector
83 stars 8 forks source link

Implement mutable iteration #3

Open steveklabnik opened 6 years ago

steveklabnik commented 6 years ago

Make an iter_mut to go along with iter.

cauebs commented 6 years ago

I gave this one a try, but it wasn't as trivial as it seemed.

error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
   --> src/lib.rs:959:20
    |
959 |         match &mut self.list.contents[next_index] {
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 954:5...
   --> src/lib.rs:954:5
    |
954 | /     fn next(&mut self) -> Option<Self::Item> {
955 | |         // do we have a next thing?
956 | |         let next_index = self.next_index?;
957 | |
...   |
967 | |         }
968 | |     }
    | |_____^
note: ...so that reference does not outlive borrowed content
   --> src/lib.rs:959:20
    |
959 |         match &mut self.list.contents[next_index] {
    |                    ^^^^^^^^^^^^^^^^^^
note: but, the lifetime must be valid for the lifetime 'a as defined on the impl at 951:6...
   --> src/lib.rs:951:6
    |
951 | impl<'a, T> Iterator for IterMut<'a, T> {
    |      ^^
    = note: ...so that the types are compatible:
            expected std::iter::Iterator
               found std::iter::Iterator
steveklabnik commented 6 years ago

Hm, interesting. I'll have to give it a shot sometime too...