html-cat 0.1.0

HTML5 parser: tokenizer + tree builder producing a Document tree of Element/Text/Comment nodes. No mut, no Rc/Arc, no interior mutability, no panics, exhaustive matches. First sub-crate of a Servo-replacement webview runtime targeting Tauri.
//! Source-position newtypes.

/// A source position: line, column, and byte offset.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Position {
    line: u32,
    column: u32,
    offset: u32,
}

impl Position {
    /// Build a position.
    #[must_use]
    pub fn new(line: u32, column: u32, offset: u32) -> Self {
        Self {
            line,
            column,
            offset,
        }
    }

    /// A synthetic position at offset zero.
    #[must_use]
    pub fn synthetic() -> Self {
        Self {
            line: 0,
            column: 0,
            offset: 0,
        }
    }

    /// The 1-based line number.
    #[must_use]
    pub fn line(&self) -> u32 {
        self.line
    }

    /// The 1-based column number.
    #[must_use]
    pub fn column(&self) -> u32 {
        self.column
    }

    /// The 0-based byte offset.
    #[must_use]
    pub fn offset(&self) -> u32 {
        self.offset
    }
}

impl std::fmt::Display for Position {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}:{}", self.line, self.column)
    }
}

/// A half-open source range `[start, end)`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Span {
    start: Position,
    end: Position,
}

impl Span {
    /// Build a span from start and end positions.
    #[must_use]
    pub fn new(start: Position, end: Position) -> Self {
        Self { start, end }
    }

    /// A synthetic span (both endpoints at offset zero).
    #[must_use]
    pub fn synthetic() -> Self {
        Self {
            start: Position::synthetic(),
            end: Position::synthetic(),
        }
    }

    /// The start position.
    #[must_use]
    pub fn start(&self) -> Position {
        self.start
    }

    /// The end position.
    #[must_use]
    pub fn end(&self) -> Position {
        self.end
    }
}

impl std::fmt::Display for Span {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}..{}", self.start, self.end)
    }
}