From a2a810f118bb2ec541f852bf02eebdf02c7326f7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Jul 2018 12:44:14 +0300 Subject: Add parent links --- src/yellow/red.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/yellow/red.rs') diff --git a/src/yellow/red.rs b/src/yellow/red.rs index 3002153ca..e0fa27e5f 100644 --- a/src/yellow/red.rs +++ b/src/yellow/red.rs @@ -16,7 +16,7 @@ pub(crate) struct RedNode { #[derive(Debug)] struct ParentData { - parent: *const RedNode, + parent: ptr::NonNull, start_offset: TextUnit, index_in_parent: usize, } @@ -30,7 +30,7 @@ impl RedNode { fn new_child( green: GreenNode, - parent: *const RedNode, + parent: ptr::NonNull, start_offset: TextUnit, index_in_parent: usize, ) -> RedNode { @@ -76,10 +76,14 @@ impl RedNode { let green_children = self.green.children(); let start_offset = self.start_offset() + green_children[..idx].iter().map(|x| x.text_len()).sum::(); - let child = RedNode::new_child(green_children[idx].clone(), self, start_offset, idx); + let child = RedNode::new_child(green_children[idx].clone(), self.into(), start_offset, idx); children[idx] = Some(Box::new(child)) } let child = children[idx].as_ref().unwrap(); ptr::NonNull::from(&**child) } + + pub(crate) fn parent(&self) -> Option> { + Some(self.parent.as_ref()?.parent) + } } -- cgit v1.2.3