Change selector in match when selector is a mutable reference
问题 I want to change enum variant based on some properties of the current enum variant in Iterator::next . I have two attempts, neither of which compile: enum Test { A(Vec<usize>), B, } impl<'a> Iterator for Test { type Item = usize; fn next(&mut self) -> Option<Self::Item> { // attempt 1 if let Test::A(ref a) = *self { if a.len() == 0 { *self = Test::B; // doesn't work because a is borrowed }; } // attempt 2 *self = match *self { Test::A(ref a) if a.len() == 0 => Test::B, _ => *self, // cannot