Lazy_load: accept an iterator instead a Vec<_> over T.
This commit is contained in:
parent
43bf8b3f15
commit
9d5fa04d49
@ -383,7 +383,7 @@ pub fn episodes_listbox(pd: Arc<Podcast>, sender: Sender<Action>) -> Result<gtk:
|
|||||||
Err(Disconnected) => return glib::Continue(false),
|
Err(Disconnected) => return glib::Continue(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
lazy_load(episodes, list.clone(), clone!(sender => move |ep| {
|
lazy_load(episodes.into_iter(), list.clone(), clone!(sender => move |ep| {
|
||||||
let w = EpisodeWidget::new(ep, sender.clone());
|
let w = EpisodeWidget::new(ep, sender.clone());
|
||||||
w.container.clone()
|
w.container.clone()
|
||||||
}));
|
}));
|
||||||
@ -396,25 +396,21 @@ pub fn episodes_listbox(pd: Arc<Podcast>, sender: Sender<Action>) -> Result<gtk:
|
|||||||
|
|
||||||
use gtk::{IsA, Widget};
|
use gtk::{IsA, Widget};
|
||||||
|
|
||||||
fn lazy_load<T, U, P, Z>(mut data: Vec<T>, container: Z, mut predicate: P)
|
fn lazy_load<T, U, P, Z>(mut data: T, container: Z, mut predicate: P)
|
||||||
where
|
where
|
||||||
T: 'static,
|
T: Iterator + 'static,
|
||||||
|
T::Item: 'static,
|
||||||
Z: ContainerExt + 'static,
|
Z: ContainerExt + 'static,
|
||||||
P: FnMut(T) -> U + 'static,
|
P: FnMut(T::Item) -> U + 'static,
|
||||||
U: IsA<Widget>,
|
U: IsA<Widget>,
|
||||||
{
|
{
|
||||||
// to use it as a stack
|
|
||||||
data.reverse();
|
|
||||||
gtk::idle_add(move || {
|
gtk::idle_add(move || {
|
||||||
if data.is_empty() {
|
data.next()
|
||||||
return glib::Continue(false);
|
.and_then(|x| {
|
||||||
}
|
container.add(&predicate(x));
|
||||||
|
Some(glib::Continue(true))
|
||||||
data.pop().map(|x| {
|
})
|
||||||
let widget = predicate(x);
|
.or(Some(glib::Continue(false)))
|
||||||
container.add(&widget);
|
.unwrap()
|
||||||
});
|
|
||||||
|
|
||||||
glib::Continue(true)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user