use std::num::NonZero;
use crate::depot::arena::linked::slots;
#[derive(Clone, Copy, Debug)]
pub struct Position {
pub(in crate::buffer) index: slots::Index,
pub(in crate::buffer) range: u32,
pub(in crate::buffer) start: usize,
}
impl Position {
pub const fn new() -> Self {
Self {
index: slots::Index::NONE,
range: u32::MAX,
start: 0,
}
}
pub unsafe fn rebase_prefix(&mut self, removed: NonZero<usize>) {
match self.start.checked_sub(removed.get()) {
Some(start) => self.start = start,
None => *self = Self::new(),
}
}
}
impl Default for Position {
fn default() -> Self {
Self::new()
}
}
const _: () = assert!(size_of::<Position>() == 2 * size_of::<usize>());