From 407ebbc552fd9a8e73a9e46873ab834c54cea967 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 31 Jul 2018 13:49:03 +0300 Subject: More fool-proof API --- src/yellow/red.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/yellow/red.rs') diff --git a/src/yellow/red.rs b/src/yellow/red.rs index 8329ec5b2..a30318c6e 100644 --- a/src/yellow/red.rs +++ b/src/yellow/red.rs @@ -61,9 +61,12 @@ impl RedNode { self.green.children().len() } - pub(crate) fn nth_child(&self, idx: usize) -> ptr::NonNull { + pub(crate) fn get_child(&self, idx: usize) -> Option> { + if idx >= self.n_children() { + return None + } match &self.children.read().unwrap()[idx] { - Some(child) => return child.into(), + Some(child) => return Some(child.into()), None => (), } let mut children = self.children.write().unwrap(); @@ -78,7 +81,7 @@ impl RedNode { RedNode::new_child(green_children[idx].clone(), self.into(), start_offset, idx); children[idx] = Some(child) } - children[idx].as_ref().unwrap().into() + Some(children[idx].as_ref().unwrap().into()) } pub(crate) fn parent(&self) -> Option> { -- cgit v1.2.3