Make the node type inside the ContextTree generic but the implementation still explicitly uses dyn OrgModeContext.

This commit is contained in:
Tom Alexander 2022-11-26 21:07:56 -05:00
parent e888c0e66f
commit f645b0cb75
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -30,17 +30,20 @@ struct Node<'r, T: 'r + ?Sized> {
parent: Link<'r, T>,
}
struct ContextTree<'r> {
struct ContextTree<'r, T: 'r + ?Sized> {
// Not using Link so the ContextTree can own this node
head: Option<Node<'r, dyn OrgModeContext<'r>>>,
head: Option<Node<'r, T>>,
}
impl<'r> ContextTree<'r> {
impl<'r> ContextTree<'r, dyn OrgModeContext<'r>> {
pub fn new() -> Self {
ContextTree { head: None }
}
pub fn with_additional_node(&'r self, new_elem: &'r dyn OrgModeContext<'r>) -> ContextTree<'r> {
pub fn with_additional_node(
&'r self,
new_elem: &'r dyn OrgModeContext<'r>,
) -> ContextTree<'r, dyn OrgModeContext<'r>> {
let new_node = Node {
elem: new_elem,
parent: self.head.as_ref(),