From f85a7710718f85f7f3ca677b19e24574f6361b03 Mon Sep 17 00:00:00 2001 From: Matthew Gordon Date: Fri, 18 Oct 2024 20:26:33 -0300 Subject: [PATCH] Add more documentation comments --- src/core/rope.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/rope.rs b/src/core/rope.rs index e348be4..ef74e29 100644 --- a/src/core/rope.rs +++ b/src/core/rope.rs @@ -71,7 +71,7 @@ impl Rope { } } - // Return the total number of lines in the text + /// Return the total number of lines in the text pub fn total_lines(&self) -> usize { match self { Rope::Branch { @@ -88,7 +88,12 @@ impl Rope { } } - pub fn join(left: Rc, right: Rc) -> Rc { + /// Concatenate two Ropes without rebalancing. + /// + /// Combines to ropes by creating a new parent node and adding `left` and + /// `right` as children. Having this separate from [Rope::concatenate()] is mostly + /// useful for testing purposes. + fn join(left: Rc, right: Rc) -> Rc { Rc::new(Rope::Branch { bytes_weight: left.total_bytes(), chars_weight: left.total_chars(), @@ -98,6 +103,7 @@ impl Rope { }) } + /// Returns true if this node is a leaf node, false otherwise pub fn is_leaf(&self) -> bool { match self { Rope::Branch { .. } => false, @@ -105,10 +111,12 @@ impl Rope { } } + /// Returns an iterater over the leaf nodes fn iter_nodes(self: Rc) -> NodeIterator { NodeIterator::new(self) } + /// Returns an iterator over the chars of the text pub fn iter_chars(self: &Rc) -> CharIterator { CharIterator::new(self) }