pub mod buffer; pub mod map_item; pub mod map_key; use { crate::core::View, std::sync::RwLock, std::{ ops::{Deref, RangeInclusive}, sync::Arc, }, }; //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> #[derive(Clone)] pub enum IndexArea { Empty, Full, Set(Vec), Range(RangeInclusive), //Procedural(Arc Box>>) } impl IndexArea { pub fn map(&self, f: impl Fn(&Key) -> T) -> IndexArea { match self { IndexArea::Empty => IndexArea::Empty, IndexArea::Full => IndexArea::Full, IndexArea::Set(v) => IndexArea::Set(v.iter().map(&f).collect()), IndexArea::Range(r) => IndexArea::Range(f(&r.start())..=f(&r.end())), } } } pub trait IndexView: View> where Key: Send + Sync, { type Item; fn get(&self, key: &Key) -> Option; fn area(&self) -> IndexArea { IndexArea::Full } } //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> impl IndexView for RwLock where Key: Send + Sync, V: IndexView + ?Sized, { type Item = V::Item; fn get(&self, key: &Key) -> Option { self.read().unwrap().get(key) } fn area(&self) -> IndexArea { self.read().unwrap().area() } } impl IndexView for Arc where Key: Send + Sync, V: IndexView + ?Sized, { type Item = V::Item; fn get(&self, key: &Key) -> Option { self.deref().get(key) } fn area(&self) -> IndexArea { self.deref().area() } } impl IndexView for Option where Key: Send + Sync, V: IndexView, { type Item = V::Item; fn get(&self, key: &Key) -> Option { self.as_ref()?.get(key) } fn area(&self) -> IndexArea { if let Some(v) = self.as_ref() { v.area() } else { IndexArea::Empty } } } //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> /* pub trait ImplIndexView : Send + Sync { type Key : Send + Sync; type Value; fn get(&self, key: &Self::Key) -> Option; fn area(&self) -> Option> { None } } impl View for V { type Msg = V::Key; } impl IndexView for V { type Item = V::Value; fn get(&self, key: &V::Key) -> Option { (self as &V).get(key) } fn area(&self) -> Option> { (self as &V).area() } } */