diff options
Diffstat (limited to 'src/rope.rs')
| -rw-r--r-- | src/rope.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/rope.rs b/src/rope.rs index 737d949..8bda5af 100644 --- a/src/rope.rs +++ b/src/rope.rs @@ -84,7 +84,7 @@ impl Rope { Rope(Node::Leaf(Leaf { unsafe_buf: Some(Rc::from(buf)), start: 0, - end: u16::try_from(buf.len()).expect("I just checked the length, it should be ok"), + end: u16::try_from(buf.len()).expect("buf.len() <= MAX_NODE_SIZE"), })) } @@ -291,6 +291,9 @@ impl Rope { } pub fn line(&self, n: usize) -> Rope { + if n > self.lines() { + panic!("Line index {} out of range 0..={}", n, self.lines()); + } self.slice(self.line_start(n), self.line_end(n)).clone() } @@ -327,13 +330,11 @@ impl Rope { return self.clone(); } match self { - Rope(Node::Leaf(l)) => { - Rope(Node::Leaf(Leaf{ - unsafe_buf: l.unsafe_buf.clone(), - start: l.start+u16::try_from(start).expect("index.start should be less than MAX_NODE_SIZE since self is a leaf"), - end: l.start+u16::try_from(end).expect("index.end should be less than or equal to MAX_NODE_SIZE since self is a leaf"), - })) - } + Rope(Node::Leaf(l)) => Rope(Node::Leaf(Leaf { + unsafe_buf: l.unsafe_buf.clone(), + start: l.start + u16::try_from(start).expect("start <= self.len()"), + end: l.start + u16::try_from(end).expect("end <= self.len()"), + })), Rope(Node::Branch(b)) => { let mut s = Rope::new(&[]); let mut start = start; |
