use crate::config::Position;
pub trait PeekableRecords {
fn get_text(&self, pos: Position) -> &str;
fn get_line(&self, pos: Position, line: usize) -> &str {
self.get_text(pos).lines().nth(line).unwrap()
}
fn count_lines(&self, pos: Position) -> usize {
self.get_text(pos).lines().count()
}
fn get_width(&self, pos: Position) -> usize {
crate::util::string::get_text_width(self.get_text(pos))
}
fn get_line_width(&self, pos: Position, line: usize) -> usize {
crate::util::string::get_line_width(self.get_line(pos, line))
}
}
impl<R> PeekableRecords for &R
where
R: PeekableRecords,
{
fn get_text(&self, pos: Position) -> &str {
R::get_text(self, pos)
}
fn get_line(&self, pos: Position, line: usize) -> &str {
R::get_line(self, pos, line)
}
fn count_lines(&self, pos: Position) -> usize {
R::count_lines(self, pos)
}
fn get_width(&self, pos: Position) -> usize {
R::get_width(self, pos)
}
fn get_line_width(&self, pos: Position, line: usize) -> usize {
R::get_line_width(self, pos, line)
}
}