Closed sophie-h closed 3 years ago
The main problem here is how to handle (and detect) iterator invalidation. You're iterating over a container that uses interior mutability, so everything can change under your feet. You could even get the same item twice if you're unlucky :)
Listbox is supposed to be used with models, especially with gtk4.
That might be true but doesn't solve the problem. You'd have the same when trying to implement an iterator on the list model.
So a proper iterator would actually implement something like get_children()
and store it to iterate over that. More like an into_iter()
. But this would do the same as get_children()
, which got removed ... for a reason I guess?
The only 'clean' solution I have in mind for ListModel
would be for every .next()
on the iterator to return a Result
that is Err
after connect_items_changed
gets triggered. (.iter()
could connect to connect_items_changed
for the time the Iter it exists)
I think we can't really do much about it here. If you want such api to exists, upstream gtk should provide it. Feel free to open an issue there.
I'm going to go ahead and close this one. Feel free to re-open if you have any suggestions for something we can safely provide.
I'm using
for c in listbox.get_children()
from gtk3-rs. This will probably become legacy code, because the handling of children can probably be done via model bindings in gtk4. However, it might still be handy to just have an iterator for children. Opinions?