You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, whenever I tried to grid.insert() a TextInput into the grid in a for loop, the compiler complains that self.cells cannot be mutably borrowed more than once, since iced TextInput::new() method takes a mutable state, and that state arg originates from &mut self.cells.
So, what is the correct way to make the 'cell' editable?
Thanks in advance.
The text was updated successfully, but these errors were encountered:
Hello, based on the problem you are describing I'm assuming you are using a for loop like for i in range to then access your cells like cells.get_mut(i)? If you call get_mut on a vector you are borrowing the whole vec mutable as long as the mutable borrowing of the element lives. Therefore you cant borrow your vector twice using this approach. You will have to mutable borrow the vector once for the whole iteration like for element in cells.iter_mut(). Using iter_mut() you will get an iterator over mutable references on each element in the vector. If you need to know the index of your element, you can just enumerate it like for (i, element) in cells.iter_mut().enumerate().
I was trying to use
grid
feature to create a table-like widget, whose cells are editable.My cell type is defined like:
and my grid struct is like:
However, whenever I tried to
grid.insert()
aTextInput
into the grid in a for loop, the compiler complains thatself.cells cannot be mutably borrowed more than once
, since icedTextInput::new()
method takes a mutable state, and that state arg originates from&mut self.cells
.So, what is the correct way to make the 'cell' editable?
Thanks in advance.
The text was updated successfully, but these errors were encountered: