dom-cat 0.1.0

Persistent DOM model: arena-backed Node tree with mutation API and CSS-selector matching. Consumes html-cat trees; selectors via css-cat. No mut, no Rc/Arc, no interior mutability, no panics, exhaustive matches. Third sub-crate of a Servo-replacement webview runtime targeting Tauri.
//! DOM error type.

use css_cat::Error as CssError;
use html_cat::Error as HtmlError;

/// All errors `dom-cat` can produce.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
    /// An HTML-parser error from the source document.
    Html(HtmlError),
    /// A CSS-parser error from the selector.
    Css(CssError),
    /// The selector source did not contain any usable selector list.
    InvalidSelector {
        /// The selector source.
        selector: String,
    },
    /// A mutation targeted a `NodeId` not present in the document.
    NodeNotFound {
        /// The raw id that failed to resolve.
        id: u64,
    },
    /// `append_child` was called on a non-element parent.
    NotAnElement {
        /// The id that was supposed to be an element.
        id: u64,
    },
    /// `append_child` was called with a child that already has a parent.
    AlreadyParented {
        /// The child id.
        child: u64,
    },
}

impl From<HtmlError> for Error {
    fn from(value: HtmlError) -> Self {
        Self::Html(value)
    }
}

impl From<CssError> for Error {
    fn from(value: CssError) -> Self {
        Self::Css(value)
    }
}

impl std::fmt::Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Html(e) => write!(f, "html error: {e}"),
            Self::Css(e) => write!(f, "css error: {e}"),
            Self::InvalidSelector { selector } => {
                write!(f, "invalid selector source: {selector:?}")
            }
            Self::NodeNotFound { id } => write!(f, "node id {id} not found"),
            Self::NotAnElement { id } => write!(f, "node id {id} is not an element"),
            Self::AlreadyParented { child } => {
                write!(f, "node id {child} already has a parent")
            }
        }
    }
}

impl std::error::Error for Error {}