Skip to content

Commit

Permalink
feat(buffer): track_caller for index_of (ratatui#1046)
Browse files Browse the repository at this point in the history
The caller put in the wrong x/y -> the caller is the cause.
  • Loading branch information
EdJoPaTo authored Apr 25, 2024
1 parent c442dfd commit 97ee102
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/buffer/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ impl Buffer {
}

/// Returns a reference to Cell at the given coordinates
#[track_caller]
pub fn get(&self, x: u16, y: u16) -> &Cell {
let i = self.index_of(x, y);
&self.content[i]
}

/// Returns a mutable reference to Cell at the given coordinates
#[track_caller]
pub fn get_mut(&mut self, x: u16, y: u16) -> &mut Cell {
let i = self.index_of(x, y);
&mut self.content[i]
Expand Down Expand Up @@ -133,6 +135,7 @@ impl Buffer {
/// // starts at (200, 100).
/// buffer.index_of(0, 0); // Panics
/// ```
#[track_caller]
pub fn index_of(&self, x: u16, y: u16) -> usize {
debug_assert!(
x >= self.area.left()
Expand Down

0 comments on commit 97ee102

Please sign in to comment.