From 854581f0bf4fbad1a41c5833f7cff08c5a9a77ac Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Fri, 6 Apr 2018 22:56:44 +0300 Subject: [PATCH] Lazy_load: Use IntoIterator for T, instead of Iterator. --- hammond-gtk/src/widgets/episode.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index 182845f..439ee2c 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -383,7 +383,7 @@ pub fn episodes_listbox(pd: Arc, sender: Sender) -> Result return glib::Continue(false), }; - lazy_load(episodes.into_iter(), list.clone(), clone!(sender => move |ep| { + lazy_load(episodes, list.clone(), clone!(sender => move |ep| { let w = EpisodeWidget::new(ep, sender.clone()); w.container.clone() })); @@ -396,21 +396,19 @@ pub fn episodes_listbox(pd: Arc, sender: Sender) -> Result(mut data: T, container: Z, mut predicate: P) +fn lazy_load(data: T, container: Z, mut predicate: P) where - T: Iterator + 'static, + T: IntoIterator + 'static, T::Item: 'static, Z: ContainerExt + 'static, P: FnMut(T::Item) -> U + 'static, U: IsA, { + let mut data = data.into_iter(); gtk::idle_add(move || { data.next() - .and_then(|x| { - container.add(&predicate(x)); - Some(glib::Continue(true)) - }) - .or(Some(glib::Continue(false))) - .unwrap() + .map(|x| container.add(&predicate(x))) + .map(|_| glib::Continue(true)) + .unwrap_or(glib::Continue(false)) }); }