maybe working with dynamic dispatch.

This commit is contained in:
Tom Alexander 2022-11-27 00:07:43 -05:00
parent a08fab1a8d
commit a55b7c42fd
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 22 additions and 22 deletions

View File

@ -77,41 +77,41 @@ pub struct ContextTree<'r, T> {
head: Option<Node<'r, T>>, head: Option<Node<'r, T>>,
} }
impl<'r, T> ContextTree<'r, T> { impl<'r, T> ContextTree<'r, T>
where
T: ContextElement,
{
pub fn new() -> Self { pub fn new() -> Self {
ContextTree { head: None } ContextTree { head: None }
} }
// pub fn with_additional_node<'s, F: ContextElement<'s>>( pub fn with_additional_node<F: ContextElement>(&'r self, element: F) -> ContextTree<'r, F> {
// &'r self, let new_node = {
// element: F, let parent: Option<&dyn NodeType<'_>> = match &self.head {
// ) -> ContextTree<'r, F> { Some(node) => Some(node),
// let new_node = { None => None,
// let parent: Option<&dyn NodeType<'_>> = match &self.head { };
// Some(node) => Some(node), Node {
// None => None, data: element,
// }; parent,
// Node { }
// data: element, };
// parent,
// }
// };
// ContextTree { ContextTree {
// head: Some(new_node), head: Some(new_node),
// } }
// } }
} }
fn test_context() { fn test_context() {
let foo = "foo"; let foo = "foo";
// let context = ContextTree::new(); let context: ContextTree<'_, PreviousElementNode> = ContextTree::new();
let child1_context = PreviousElementNode { dummy: foo }; let child1_context = PreviousElementNode { dummy: foo };
// let child1 = context.with_additional_node(child1_context); let child1 = context.with_additional_node(child1_context);
let child2_context = FailMatcherNode { let child2_context = FailMatcherNode {
fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)), fail_matcher: ChainBehavior::AndParent(Some(&recognize_bold_end)),
}; };
// let child2 = child1.with_additional_node(child2_context); let child2 = child1.with_additional_node(child2_context);
} }
fn recognize_bold_end(input: &str) -> Res<&str, &str> { fn recognize_bold_end(input: &str) -> Res<&str, &str> {