o3 0.61.0

shared-nothing primitives
Documentation
use std::num::NonZero;

use crate::depot::arena::linked::slots;

/// A movable traversal checkpoint containing no borrowed addresses.
/// Prefix removal requires rebasing before the same source is resumed.
#[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,
        }
    }

    /// # Safety
    /// Before removal, this checkpoint was valid for the same live source.
    /// Since its last initialization, resume, or rebase, exactly `removed` bytes of
    /// whole leading spans were removed; surviving node identities, forward links,
    /// range identities and bytes are unchanged.
    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>());