From 03dc9f113321f369fc0a115a21e7b31cd99339a2 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 10 Mar 2024 19:27:51 +0100 Subject: [PATCH] add ReprTreeExt trait for Arc> --- lib-nested-core/src/repr_tree/mod.rs | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lib-nested-core/src/repr_tree/mod.rs b/lib-nested-core/src/repr_tree/mod.rs index 3ea0c0c..4ce5391 100644 --- a/lib-nested-core/src/repr_tree/mod.rs +++ b/lib-nested-core/src/repr_tree/mod.rs @@ -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, port: AnyOuterViewPort); + fn insert_branch(&mut self, repr: Arc>); + + fn descend(&self, target_type: impl Into) -> Option>>; + fn descend_ladder(&self, ladder: impl Iterator) -> Option>>; + + fn view_char(&self) -> OuterViewPort>; + fn view_u8(&self) -> OuterViewPort>; + fn view_u64(&self) -> OuterViewPort>; +} + +impl ReprTreeExt for Arc> { + fn get_type(&self) -> TypeTerm { + self.read().unwrap().get_type().clone() + } + + fn insert_leaf(&mut self, type_ladder: impl Iterator, port: AnyOuterViewPort) { + self.write().unwrap().insert_leaf(type_ladder, port) + } + + fn insert_branch(&mut self, repr: Arc>) { + self.write().unwrap().insert_branch(repr) + } + + fn descend(&self, target_type: impl Into) -> Option>> { + self.read().unwrap().descend(target_type) + } + + fn descend_ladder(&self, ladder: impl Iterator) -> Option>> { + ReprTree::descend_ladder(self, ladder) + } + + fn view_char(&self) -> OuterViewPort> { + self.read().unwrap().view_char() + } + + fn view_u8(&self) -> OuterViewPort> { + self.read().unwrap().view_u8() + } + + fn view_u64(&self) -> OuterViewPort> { + self.read().unwrap().view_u64() + } +} + //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> impl ReprTree { @@ -108,6 +156,10 @@ impl ReprTree { self.get_port::>().expect("no char-view available") } + pub fn view_u8(&self) -> OuterViewPort> { + self.get_port::>().expect("no u8-view available") + } + pub fn view_u64(&self) -> OuterViewPort> { self.get_port::>().expect("no u64-view available") }