OK, with a little bit of tweaking I have come up with a version
that seems to work:

    struct List {
        payload1: int,
        next: Option<~List>,
        payload2: f64
    }

    struct ListMutIterator<'a> {
        elem: Option<&'a mut List>
    }

    impl<'a> Iterator<(&'a mut int, &'a mut f64)> for ListMutIterator<'a> {
        fn next(&mut self) -> Option<(&'a mut int, &'a mut f64)> {
            let elem = std::util::replace(self, ListMutIterator{elem:None}); // 
I think this might be necessary to get around the borrow checker.

            let (ret, next) = match elem {
                ListMutIterator{elem: Some(&List { payload1: ref mut payload1, 
next: ref mut next, payload2: ref mut payload2 })} => {
                     (Some((payload1, payload2)), match *next {
                        None => None,
                         Some(ref mut p) => Some(&mut **p)
                     })
                }
                ListMutIterator{elem: None} => (None, None)
            };
            *self = ListMutIterator{elem:next};
            ret
        }
    }

Perhaps dlist should be updated to use this implementation strategy?

Edward
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to