2021-01-12 23:09:46 +01:00
|
|
|
|
2021-01-12 23:13:27 +01:00
|
|
|
pub mod map_item;
|
2021-01-16 13:57:06 +01:00
|
|
|
pub mod map_key;
|
2021-01-12 23:13:27 +01:00
|
|
|
|
2021-01-06 21:35:46 +01:00
|
|
|
use {
|
|
|
|
std::{
|
|
|
|
sync::{Arc, RwLock},
|
2021-01-16 13:57:06 +01:00
|
|
|
ops::Deref,
|
2021-01-06 21:35:46 +01:00
|
|
|
},
|
|
|
|
crate::core::View
|
|
|
|
};
|
|
|
|
|
|
|
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
|
|
|
|
|
|
|
pub trait IndexView<Key> : View<Msg = Key> {
|
|
|
|
type Item;
|
|
|
|
|
|
|
|
fn get(&self, key: &Key) -> Self::Item;
|
|
|
|
|
2021-01-16 15:31:37 +01:00
|
|
|
// todo: AreaIterator enum to switch between Allocated and Procedural area
|
2021-01-16 13:57:06 +01:00
|
|
|
fn area(&self) -> Option<Vec<Key>> {
|
2021-01-06 21:35:46 +01:00
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
|
|
|
|
|
|
|
impl<Key, V: IndexView<Key>> IndexView<Key> for RwLock<V> {
|
|
|
|
type Item = V::Item;
|
|
|
|
|
|
|
|
fn get(&self, key: &Key) -> Self::Item {
|
|
|
|
self.read().unwrap().get(key)
|
|
|
|
}
|
|
|
|
|
2021-01-16 13:57:06 +01:00
|
|
|
fn area(&self) -> Option<Vec<Key>> {
|
|
|
|
self.read().unwrap().area()
|
2021-01-06 21:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Key, V: IndexView<Key>> IndexView<Key> for Arc<V> {
|
|
|
|
type Item = V::Item;
|
|
|
|
|
|
|
|
fn get(&self, key: &Key) -> Self::Item {
|
|
|
|
self.deref().get(key)
|
|
|
|
}
|
2021-01-16 13:57:06 +01:00
|
|
|
|
|
|
|
fn area(&self) -> Option<Vec<Key>> {
|
|
|
|
self.deref().area()
|
2021-01-06 21:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
|
|
|
|
|
|
|
pub trait ImplIndexView : Send + Sync {
|
|
|
|
type Key;
|
|
|
|
type Value;
|
|
|
|
|
|
|
|
fn get(&self, key: &Self::Key) -> Self::Value;
|
2021-01-16 13:57:06 +01:00
|
|
|
fn area(&self) -> Option<Vec<Self::Key>> {
|
2021-01-06 21:35:46 +01:00
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<V: ImplIndexView> View for V {
|
|
|
|
type Msg = V::Key;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<V: ImplIndexView> IndexView<V::Key> for V {
|
|
|
|
type Item = V::Value;
|
|
|
|
|
|
|
|
fn get(&self, key: &V::Key) -> Self::Item {
|
|
|
|
(self as &V).get(key)
|
|
|
|
}
|
|
|
|
|
2021-01-16 13:57:06 +01:00
|
|
|
fn area(&self) -> Option<Vec<V::Key>> {
|
|
|
|
(self as &V).area()
|
2021-01-06 21:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-16 13:57:06 +01:00
|
|
|
|