feat(buffer): track_caller for index_of (#1046)

The caller put in the wrong x/y -> the caller is the cause.
This commit is contained in:
EdJoPaTo 2024-04-26 01:23:09 +02:00 committed by GitHub
parent c442dfd1ad
commit 97ee102f17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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]
@ -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()