add ReprTreeExt trait for Arc<Rwlock<>>
This commit is contained in:
parent
d7d0a46c7b
commit
03dc9f1133
1 changed files with 52 additions and 0 deletions
|
@ -38,6 +38,54 @@ impl std::fmt::Debug for ReprTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait ReprTreeExt {
|
||||||
|
fn get_type(&self) -> TypeTerm;
|
||||||
|
|
||||||
|
fn insert_leaf(&mut self, type_ladder: impl Iterator<Item = TypeTerm>, port: AnyOuterViewPort);
|
||||||
|
fn insert_branch(&mut self, repr: Arc<RwLock<ReprTree>>);
|
||||||
|
|
||||||
|
fn descend(&self, target_type: impl Into<TypeTerm>) -> Option<Arc<RwLock<ReprTree>>>;
|
||||||
|
fn descend_ladder(&self, ladder: impl Iterator<Item = TypeTerm>) -> Option<Arc<RwLock<ReprTree>>>;
|
||||||
|
|
||||||
|
fn view_char(&self) -> OuterViewPort<dyn SingletonView<Item = char>>;
|
||||||
|
fn view_u8(&self) -> OuterViewPort<dyn SingletonView<Item = u8>>;
|
||||||
|
fn view_u64(&self) -> OuterViewPort<dyn SingletonView<Item = u64>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ReprTreeExt for Arc<RwLock<ReprTree>> {
|
||||||
|
fn get_type(&self) -> TypeTerm {
|
||||||
|
self.read().unwrap().get_type().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert_leaf(&mut self, type_ladder: impl Iterator<Item = TypeTerm>, port: AnyOuterViewPort) {
|
||||||
|
self.write().unwrap().insert_leaf(type_ladder, port)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert_branch(&mut self, repr: Arc<RwLock<ReprTree>>) {
|
||||||
|
self.write().unwrap().insert_branch(repr)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn descend(&self, target_type: impl Into<TypeTerm>) -> Option<Arc<RwLock<ReprTree>>> {
|
||||||
|
self.read().unwrap().descend(target_type)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn descend_ladder(&self, ladder: impl Iterator<Item = TypeTerm>) -> Option<Arc<RwLock<ReprTree>>> {
|
||||||
|
ReprTree::descend_ladder(self, ladder)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view_char(&self) -> OuterViewPort<dyn SingletonView<Item = char>> {
|
||||||
|
self.read().unwrap().view_char()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view_u8(&self) -> OuterViewPort<dyn SingletonView<Item = u8>> {
|
||||||
|
self.read().unwrap().view_u8()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view_u64(&self) -> OuterViewPort<dyn SingletonView<Item = u64>> {
|
||||||
|
self.read().unwrap().view_u64()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||||
|
|
||||||
impl ReprTree {
|
impl ReprTree {
|
||||||
|
@ -108,6 +156,10 @@ impl ReprTree {
|
||||||
self.get_port::<dyn SingletonView<Item = char>>().expect("no char-view available")
|
self.get_port::<dyn SingletonView<Item = char>>().expect("no char-view available")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn view_u8(&self) -> OuterViewPort<dyn SingletonView<Item = u8>> {
|
||||||
|
self.get_port::<dyn SingletonView<Item = u8>>().expect("no u8-view available")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn view_u64(&self) -> OuterViewPort<dyn SingletonView<Item = u64>> {
|
pub fn view_u64(&self) -> OuterViewPort<dyn SingletonView<Item = u64>> {
|
||||||
self.get_port::<dyn SingletonView<Item = u64>>().expect("no u64-view available")
|
self.get_port::<dyn SingletonView<Item = u64>>().expect("no u64-view available")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue