#How can I use a mutable reference mutably after using .iter()?

9 messages · Page 1 of 1 (latest)

twin spade
#
    pub fn cleanup(&mut self) {
        for (index, descriptor) in self.descriptors.iter().enumerate() {
            if descriptor.default_axis_value == 0. && descriptor.axis.press.released() {
                self.descriptors.remove(index);
            }
        }
    }
#

I'm getting a message that I can't use self as mutable again

#

"Immutable borrows occurs here" is pointing to the iter call

#

cannot borrow `self.descriptors` as mutable because it is also borrowed as immutable

lapis seal
twin spade
#

oh

#

i forgot that this function exists xd

#

thank you

lapis seal
#

Though remember to invert the condition, because the condition should be true for items you want to keep