Cannot obtain a mutable reference when iterating a recursive structure: cannot borrow as mutable more than once at a time

前端 未结 4 1765
盖世英雄少女心
盖世英雄少女心 2020-11-22 07:05

I\'m trying to navigate a recursive data structure iteratively in order to insert elements at a certain position. To my limited understanding, this means taking a mutable re

4条回答
  •  情话喂你
    2020-11-22 07:49

    It works:

    fn back(&mut self) -> &mut Link {
        let mut anchor = &mut self.root;
        while anchor.is_some(){
            anchor = &mut {anchor}.as_mut().unwrap().next;
        }
        anchor
    }
    

提交回复
热议问题