diff options
author | Aleksey Kladov <[email protected]> | 2018-07-31 11:49:03 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-07-31 11:49:03 +0100 |
commit | 407ebbc552fd9a8e73a9e46873ab834c54cea967 (patch) | |
tree | b68be1e094307d54ac060181a8c752d9d7fb1db8 /src/yellow/red.rs | |
parent | 87b5e14c75dbc02b5bc610dfa33d5789570df5db (diff) |
More fool-proof API
Diffstat (limited to 'src/yellow/red.rs')
-rw-r--r-- | src/yellow/red.rs | 9 |
1 files changed, 6 insertions, 3 deletions
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 { | |||
61 | self.green.children().len() | 61 | self.green.children().len() |
62 | } | 62 | } |
63 | 63 | ||
64 | pub(crate) fn nth_child(&self, idx: usize) -> ptr::NonNull<RedNode> { | 64 | pub(crate) fn get_child(&self, idx: usize) -> Option<ptr::NonNull<RedNode>> { |
65 | if idx >= self.n_children() { | ||
66 | return None | ||
67 | } | ||
65 | match &self.children.read().unwrap()[idx] { | 68 | match &self.children.read().unwrap()[idx] { |
66 | Some(child) => return child.into(), | 69 | Some(child) => return Some(child.into()), |
67 | None => (), | 70 | None => (), |
68 | } | 71 | } |
69 | let mut children = self.children.write().unwrap(); | 72 | let mut children = self.children.write().unwrap(); |
@@ -78,7 +81,7 @@ impl RedNode { | |||
78 | RedNode::new_child(green_children[idx].clone(), self.into(), start_offset, idx); | 81 | RedNode::new_child(green_children[idx].clone(), self.into(), start_offset, idx); |
79 | children[idx] = Some(child) | 82 | children[idx] = Some(child) |
80 | } | 83 | } |
81 | children[idx].as_ref().unwrap().into() | 84 | Some(children[idx].as_ref().unwrap().into()) |
82 | } | 85 | } |
83 | 86 | ||
84 | pub(crate) fn parent(&self) -> Option<ptr::NonNull<RedNode>> { | 87 | pub(crate) fn parent(&self) -> Option<ptr::NonNull<RedNode>> { |