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.
//! The top-level [`Document`] handle wrapping an arena.

use crate::node::{Arena, Node, NodeId};

/// A complete DOM document.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Document {
    arena: Arena,
    root: NodeId,
}

impl Document {
    /// Build a document from a populated arena and its root id.
    #[must_use]
    pub fn new(arena: Arena, root: NodeId) -> Self {
        Self { arena, root }
    }

    /// The arena.
    #[must_use]
    pub fn arena(&self) -> &Arena {
        &self.arena
    }

    /// The document-root id.
    #[must_use]
    pub fn root(&self) -> NodeId {
        self.root
    }

    /// Replace the arena.  Used by mutation operations that need to
    /// thread a fresh arena through the document.
    #[must_use]
    pub fn with_arena(self, arena: Arena) -> Self {
        Self { arena, ..self }
    }

    /// Look up `id` in the arena.
    #[must_use]
    pub fn get(&self, id: NodeId) -> Option<&Node> {
        self.arena.get(id)
    }
}