#[derive(Debug)]
pub struct LineCursor {
offset: Line,
baseline: Line,
}
impl LineCursor {
pub fn new(relative: Line, absolute: Line) -> Self {
Self {
offset: relative,
baseline: absolute,
}
}
pub fn relative_offset(&self) -> Line {
self.offset
}
pub fn relative_offset_mut_ref(&mut self) -> &mut Line {
&mut self.offset
}
pub fn increment_by(&mut self, amount: Line) {
self.offset = match self.offset.checked_add(amount) {
Some(line) => line,
None => {
eprintln!("Tried incrementing relative line offset by {} on line {} but overflowed.\nComputer says no...\n", amount, self.sum_total());
panic!()
}
};
}
pub fn sum_total(&self) -> Line {
self.offset + self.baseline
}
}
pub type Line = usize;