Skip to main content

Dom

Struct Dom 

Source
pub struct Dom { /* private fields */ }
Expand description

Arena-allocated DOM tree. All nodes live in a flat Vec, referenced by NodeId.

Implementations§

Source§

impl Dom

Source

pub fn new() -> Self

Create a new DOM with a Document node at index 0.

Source

pub fn document(&self) -> NodeId

Get the document node ID.

Source

pub fn get(&self, id: NodeId) -> Option<&Node>

Get a reference to a node by ID.

Source

pub fn get_mut(&mut self, id: NodeId) -> Option<&mut Node>

Get a mutable reference to a node by ID.

Source

pub fn len(&self) -> usize

Total number of live nodes.

Source

pub fn is_empty(&self) -> bool

Source

pub fn create_element( &mut self, name: QualName, attrs: Vec<Attribute>, ) -> NodeId

Source

pub fn create_text(&mut self, text: String) -> NodeId

Source

pub fn create_comment(&mut self, text: String) -> NodeId

Source

pub fn create_document_fragment(&mut self) -> NodeId

Source

pub fn create_shadow_root( &mut self, host: NodeId, mode: ShadowRootMode, ) -> NodeId

Create a shadow root and attach it to the given host element.

Source

pub fn allocate_pi(&mut self, target: String, data: String) -> NodeId

Source

pub fn create_doctype( &mut self, name: String, public_id: String, system_id: String, ) -> NodeId

Source

pub fn append_child(&mut self, parent: NodeId, child: NodeId)

Append child as the last child of parent.

Cycle-safe: if child is an ancestor of parent, the mutation is a no-op.

Source

pub fn insert_before( &mut self, parent: NodeId, child: NodeId, reference: NodeId, )

Insert child before reference (which must be a child of parent).

Source

pub fn detach(&mut self, id: NodeId)

Detach a node from its parent (but keep it in the arena).

Source

pub fn remove(&mut self, id: NodeId)

Remove a node from the arena entirely (recycles its slot).

Source

pub fn reparent_children(&mut self, source: NodeId, target: NodeId)

Move all children of source to become children of target.

Source

pub fn children(&self, parent: NodeId) -> Vec<NodeId>

Iterate over child node IDs.

Source

pub fn child_elements(&self, parent: NodeId) -> Vec<NodeId>

Iterate over child element node IDs (skip text/comment nodes).

Source

pub fn text_content(&self, id: NodeId) -> String

Get text content of a subtree.

Source

pub fn set_text_content(&mut self, id: NodeId, text: &str)

Set text content: remove all children, add a single text node.

Source

pub fn get_element_by_id(&self, id_value: &str) -> Option<NodeId>

Find an element by ID attribute (tree walk from document root).

Source

pub fn get_elements_by_tag_name(&self, root: NodeId, tag: &str) -> Vec<NodeId>

Find elements by tag name (case-insensitive).

Source

pub fn get_elements_by_class_name( &self, root: NodeId, class: &str, ) -> Vec<NodeId>

Find elements by class name.

Source

pub fn serialize_html(&self, id: NodeId) -> String

Serialize a subtree as HTML.

Source

pub fn serialize_inner_html(&self, id: NodeId) -> String

Serialize children of a node as HTML (for innerHTML getter).

Source

pub fn merge_subtree(&mut self, source: &Dom, source_root: NodeId) -> NodeId

Copy a subtree from another Dom into this one. Returns the new root NodeId.

Source

pub fn node_type(&self, id: NodeId) -> u32

Get the node type number (matches DOM spec nodeType).

Trait Implementations§

Source§

impl Debug for Dom

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Dom

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Dom

§

impl RefUnwindSafe for Dom

§

impl Send for Dom

§

impl Sync for Dom

§

impl Unpin for Dom

§

impl UnsafeUnpin for Dom

§

impl UnwindSafe for Dom

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more