fix warnings & format
This commit is contained in:
parent
bf8a949cdd
commit
411b773ab5
61 changed files with 2759 additions and 2741 deletions
nested/src/index
|
@ -1,33 +1,22 @@
|
|||
pub use {
|
||||
std::{
|
||||
sync::Arc,
|
||||
boxed::Box
|
||||
},
|
||||
std::sync::RwLock,
|
||||
crate::{
|
||||
core::{
|
||||
View,
|
||||
Observer,
|
||||
ObserverExt,
|
||||
ObserverBroadcast,
|
||||
ViewPort,
|
||||
InnerViewPort,
|
||||
OuterViewPort
|
||||
InnerViewPort, Observer, ObserverBroadcast, ObserverExt, OuterViewPort, View, ViewPort,
|
||||
},
|
||||
index::{IndexArea, IndexView}
|
||||
}
|
||||
index::{IndexArea, IndexView},
|
||||
},
|
||||
std::sync::RwLock,
|
||||
std::{boxed::Box, sync::Arc},
|
||||
};
|
||||
|
||||
impl<Key, Item> OuterViewPort<dyn IndexView<Key, Item = Item>>
|
||||
where Key: Clone + Send + Sync + 'static,
|
||||
Item: Send + Sync + 'static
|
||||
where
|
||||
Key: Clone + Send + Sync + 'static,
|
||||
Item: Send + Sync + 'static,
|
||||
{
|
||||
pub fn map_item<
|
||||
DstItem: 'static,
|
||||
F: Fn(&Key, &Item) -> DstItem + Send + Sync + 'static
|
||||
>(
|
||||
pub fn map_item<DstItem: 'static, F: Fn(&Key, &Item) -> DstItem + Send + Sync + 'static>(
|
||||
&self,
|
||||
f: F
|
||||
f: F,
|
||||
) -> OuterViewPort<dyn IndexView<Key, Item = DstItem>> {
|
||||
let port = ViewPort::new();
|
||||
port.add_update_hook(Arc::new(self.0.clone()));
|
||||
|
@ -39,32 +28,29 @@ where Key: Clone + Send + Sync + 'static,
|
|||
}
|
||||
|
||||
pub struct MapIndexItem<Key, DstItem, SrcView, F>
|
||||
where Key: Clone + Send + Sync,
|
||||
SrcView: IndexView<Key> + ?Sized,
|
||||
F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync
|
||||
where
|
||||
Key: Clone + Send + Sync,
|
||||
SrcView: IndexView<Key> + ?Sized,
|
||||
F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync,
|
||||
{
|
||||
src_view: Option<Arc<SrcView>>,
|
||||
f: F,
|
||||
cast: Arc<RwLock<ObserverBroadcast<dyn IndexView<Key, Item = DstItem>>>>
|
||||
cast: Arc<RwLock<ObserverBroadcast<dyn IndexView<Key, Item = DstItem>>>>,
|
||||
}
|
||||
|
||||
impl<Key, DstItem, SrcView, F> MapIndexItem<Key, DstItem, SrcView, F>
|
||||
where Key: Clone + Send + Sync + 'static,
|
||||
DstItem: 'static,
|
||||
SrcView: IndexView<Key> + ?Sized + 'static,
|
||||
F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync + 'static
|
||||
where
|
||||
Key: Clone + Send + Sync + 'static,
|
||||
DstItem: 'static,
|
||||
SrcView: IndexView<Key> + ?Sized + 'static,
|
||||
F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync + 'static,
|
||||
{
|
||||
fn new(
|
||||
port: InnerViewPort<dyn IndexView<Key, Item = DstItem>>,
|
||||
f: F
|
||||
) -> Arc<RwLock<Self>> {
|
||||
let map = Arc::new(RwLock::new(
|
||||
MapIndexItem {
|
||||
src_view: None,
|
||||
f,
|
||||
cast: port.get_broadcast()
|
||||
}
|
||||
));
|
||||
fn new(port: InnerViewPort<dyn IndexView<Key, Item = DstItem>>, f: F) -> Arc<RwLock<Self>> {
|
||||
let map = Arc::new(RwLock::new(MapIndexItem {
|
||||
src_view: None,
|
||||
f,
|
||||
cast: port.get_broadcast(),
|
||||
}));
|
||||
|
||||
port.set_view(Some(map.clone()));
|
||||
map
|
||||
|
@ -72,22 +58,27 @@ where Key: Clone + Send + Sync + 'static,
|
|||
}
|
||||
|
||||
impl<Key, DstItem, SrcView, F> View for MapIndexItem<Key, DstItem, SrcView, F>
|
||||
where Key: Clone + Send + Sync,
|
||||
SrcView: IndexView<Key> + ?Sized,
|
||||
F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync
|
||||
where
|
||||
Key: Clone + Send + Sync,
|
||||
SrcView: IndexView<Key> + ?Sized,
|
||||
F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync,
|
||||
{
|
||||
type Msg = IndexArea<Key>;
|
||||
}
|
||||
|
||||
impl<Key, DstItem, SrcView, F> IndexView<Key> for MapIndexItem<Key, DstItem, SrcView, F>
|
||||
where Key: Clone + Send + Sync,
|
||||
SrcView: IndexView<Key> + ?Sized,
|
||||
F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync
|
||||
where
|
||||
Key: Clone + Send + Sync,
|
||||
SrcView: IndexView<Key> + ?Sized,
|
||||
F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync,
|
||||
{
|
||||
type Item = DstItem;
|
||||
|
||||
fn get(&self, key: &Key) -> Option<Self::Item> {
|
||||
self.src_view.get(key).as_ref().map(|item| (self.f)(key, item))
|
||||
self.src_view
|
||||
.get(key)
|
||||
.as_ref()
|
||||
.map(|item| (self.f)(key, item))
|
||||
}
|
||||
|
||||
fn area(&self) -> IndexArea<Key> {
|
||||
|
@ -96,9 +87,10 @@ where Key: Clone + Send + Sync,
|
|||
}
|
||||
|
||||
impl<Key, DstItem, SrcView, F> Observer<SrcView> for MapIndexItem<Key, DstItem, SrcView, F>
|
||||
where Key: Clone + Send + Sync,
|
||||
SrcView: IndexView<Key> + ?Sized,
|
||||
F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync
|
||||
where
|
||||
Key: Clone + Send + Sync,
|
||||
SrcView: IndexView<Key> + ?Sized,
|
||||
F: Fn(&Key, &SrcView::Item) -> DstItem + Send + Sync,
|
||||
{
|
||||
fn reset(&mut self, view: Option<Arc<SrcView>>) {
|
||||
let old_area = self.area();
|
||||
|
@ -113,4 +105,3 @@ where Key: Clone + Send + Sync,
|
|||
self.cast.notify(area);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue