diff --git a/src/buffer.rs b/src/buffer.rs index f573e45..3601746 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -766,7 +766,7 @@ impl Buffer { loop { let (Some(line_range), Some((attrs, span_range))) = (&maybe_line, &maybe_span) else { // this is reached only if this text is empty - if self.lines.len() <= line_count { + if self.lines.len() == line_count { self.lines.push(BufferLine::empty()); } self.lines[line_count].reset_new( @@ -817,7 +817,7 @@ impl Buffer { .unwrap_or_default(); let prev_attrs_list = core::mem::replace(&mut attrs_list, next_attrs_list); let prev_line_string = core::mem::replace(&mut line_string, next_line_string); - if self.lines.len() <= line_count { + if self.lines.len() == line_count { self.lines.push(BufferLine::empty()); } self.lines[line_count].reset_new( @@ -829,7 +829,7 @@ impl Buffer { line_count += 1; } else { // finalize the final line - if self.lines.len() <= line_count { + if self.lines.len() == line_count { self.lines.push(BufferLine::empty()); } self.lines[line_count].reset_new(line_string, line_ending, attrs_list, shaping); diff --git a/src/buffer_line.rs b/src/buffer_line.rs index 1ac71cb..0800707 100644 --- a/src/buffer_line.rs +++ b/src/buffer_line.rs @@ -309,7 +309,7 @@ impl BufferLine { /// Makes an empty buffer line. /// - /// The buffer line is in an invalid state after this is called. See [`Self::reclaim_new`]. + /// The buffer line is in an invalid state after this is called. See [`Self::reset_new`]. pub(crate) fn empty() -> Self { Self { text: String::default(), @@ -325,14 +325,14 @@ impl BufferLine { /// Reclaim attributes list memory that isn't needed any longer. /// - /// The buffer line is in an invalid state after this is called. See [`Self::reclaim_new`]. + /// The buffer line is in an invalid state after this is called. See [`Self::reset_new`]. pub(crate) fn reclaim_attrs(&mut self) -> AttrsList { std::mem::replace(&mut self.attrs_list, AttrsList::new(Attrs::new())) } /// Reclaim text memory that isn't needed any longer. /// - /// The buffer line is in an invalid state after this is called. See [`Self::reclaim_new`]. + /// The buffer line is in an invalid state after this is called. See [`Self::reset_new`]. pub(crate) fn reclaim_text(&mut self) -> String { let mut text = std::mem::take(&mut self.text); text.clear(); diff --git a/src/cached.rs b/src/cached.rs index 38c5eb8..b9b0ba2 100644 --- a/src/cached.rs +++ b/src/cached.rs @@ -9,6 +9,7 @@ pub enum Cached { } impl Cached { + /// Gets the value if in state `Self::Used`. pub fn get(&self) -> Option<&T> { match self { Self::Empty | Self::Unused(_) => None, @@ -16,6 +17,7 @@ impl Cached { } } + /// Gets the value mutably if in state `Self::Used`. pub fn get_mut(&mut self) -> Option<&mut T> { match self { Self::Empty | Self::Unused(_) => None, @@ -23,6 +25,7 @@ impl Cached { } } + /// Checks if the value is empty or unused. pub fn is_unused(&self) -> bool { match self { Self::Empty | Self::Unused(_) => true, @@ -30,6 +33,7 @@ impl Cached { } } + /// Checks if the value is used (i.e. cached for access). pub fn is_used(&self) -> bool { match self { Self::Empty | Self::Unused(_) => false, @@ -37,6 +41,7 @@ impl Cached { } } + /// Takes the buffered value if in state `Self::Unused`. pub fn take_unused(&mut self) -> Option { if matches!(*self, Self::Unused(_)) { let Self::Unused(val) = std::mem::replace(self, Self::Empty) else { @@ -48,6 +53,7 @@ impl Cached { } } + /// Takes the cached value if in state `Self::Used`. pub fn take_used(&mut self) -> Option { if matches!(*self, Self::Used(_)) { let Self::Used(val) = std::mem::replace(self, Self::Empty) else { @@ -59,12 +65,14 @@ impl Cached { } } + /// Moves the value from `Self::Used` to `Self::Unused`. pub fn set_unused(&mut self) { if matches!(*self, Self::Used(_)) { *self = Self::Unused(self.take_used().unwrap()); } } + /// Sets the value to `Self::Used`. pub fn set_used(&mut self, val: T) { *self = Self::Used(val); }