From d1c523335ba9324b302d2902078520e69f2fb3e3 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Mon, 18 Jan 2021 16:59:35 +0100 Subject: [PATCH] MapIndexItem: pass key and item to function --- src/index/map_item.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index/map_item.rs b/src/index/map_item.rs index f1d4b59..28bc582 100644 --- a/src/index/map_item.rs +++ b/src/index/map_item.rs @@ -20,7 +20,7 @@ pub use { impl OuterViewPort> { pub fn map_item< DstItem: 'static, - F: Fn(&Item) -> DstItem + Send + Sync + 'static + F: Fn(&Key, &Item) -> DstItem + Send + Sync + 'static >( &self, f: F @@ -34,7 +34,7 @@ impl OuterViewPort> pub struct MapIndexItem where SrcView: IndexView + ?Sized, - F: Fn(&SrcView::Item) -> DstItem + Send + Sync + F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync { src_view: Option>, f: F, @@ -45,7 +45,7 @@ impl MapIndexItem where Key: 'static, DstItem: 'static, SrcView: IndexView + ?Sized + 'static, - F: Fn(&SrcView::Item) -> DstItem + Send + Sync + 'static + F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync + 'static { fn new( port: InnerViewPort>, @@ -66,19 +66,19 @@ where Key: 'static, impl View for MapIndexItem where SrcView: IndexView + ?Sized, - F: Fn(&SrcView::Item) -> DstItem + Send + Sync + F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync { type Msg = Key; } impl IndexView for MapIndexItem where SrcView: IndexView + ?Sized, - F: Fn(&SrcView::Item) -> DstItem + Send + Sync + F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync { type Item = DstItem; fn get(&self, key: &Key) -> Option { - self.src_view.as_ref()?.get(key).as_ref().map(&self.f) + self.src_view.as_ref()?.get(key).as_ref().map(|item| (self.f)(key, item)) } fn area(&self) -> Option> { @@ -88,7 +88,7 @@ where SrcView: IndexView + ?Sized, impl Observer for MapIndexItem where SrcView: IndexView + ?Sized, - F: Fn(&SrcView::Item) -> DstItem + Send + Sync + F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync { fn reset(&mut self, view: Option>) { let old_area = self.area();