Struct tauri_utils::html::NodeRef

source ·
pub struct NodeRef(pub Rc<Node>);
Expand description

A strong reference to a node.

A node is destroyed when the last strong reference to it dropped.

Each node holds a strong reference to its first child and next sibling (if any), but only a weak reference to its last child, previous sibling, and parent. This is to avoid strong reference cycles, which would cause memory leaks.

As a result, a single NodeRef is sufficient to keep alive a node and nodes that are after it in tree order (its descendants, its following siblings, and their descendants) but not other nodes in a tree.

To avoid detroying nodes prematurely, programs typically hold a strong reference to the root of a document until they’re done with that document.

Tuple Fields§

§0: Rc<Node>

Implementations§

source§

impl NodeRef

source

pub fn inclusive_ancestors(&self) -> Ancestors

Return an iterator of references to this node and its ancestors.

source

pub fn ancestors(&self) -> Ancestors

Return an iterator of references to this node’s ancestors.

source

pub fn inclusive_preceding_siblings(&self) -> Rev<Siblings>

Return an iterator of references to this node and the siblings before it.

source

pub fn preceding_siblings(&self) -> Rev<Siblings>

Return an iterator of references to this node’s siblings before it.

source

pub fn inclusive_following_siblings(&self) -> Siblings

Return an iterator of references to this node and the siblings after it.

source

pub fn following_siblings(&self) -> Siblings

Return an iterator of references to this node’s siblings after it.

source

pub fn children(&self) -> Siblings

Return an iterator of references to this node’s children.

source

pub fn inclusive_descendants(&self) -> Descendants

Return an iterator of references to this node and its descendants, in tree order.

Parent nodes appear before the descendants.

Note: this is the NodeEdge::Start items from traverse().

source

pub fn descendants(&self) -> Descendants

Return an iterator of references to this node’s descendants, in tree order.

Parent nodes appear before the descendants.

Note: this is the NodeEdge::Start items from traverse().

source

pub fn traverse_inclusive(&self) -> Traverse

Return an iterator of the start and end edges of this node and its descendants, in tree order.

source

pub fn traverse(&self) -> Traverse

Return an iterator of the start and end edges of this node’s descendants, in tree order.

source

pub fn select( &self, selectors: &str, ) -> Result<Select<Elements<Descendants>>, ()>

Return an iterator of the inclusive descendants element that match the given selector list.

source

pub fn select_first( &self, selectors: &str, ) -> Result<NodeDataRef<ElementData>, ()>

Return the first inclusive descendants element that match the given selector list.

source§

impl NodeRef

source

pub fn into_element_ref(self) -> Option<NodeDataRef<ElementData>>

If this node is an element, return a strong reference to element-specific data.

source

pub fn into_text_ref(self) -> Option<NodeDataRef<RefCell<String>>>

If this node is a text node, return a strong reference to its contents.

source

pub fn into_comment_ref(self) -> Option<NodeDataRef<RefCell<String>>>

If this node is a comment, return a strong reference to its contents.

source

pub fn into_doctype_ref(self) -> Option<NodeDataRef<Doctype>>

If this node is a doctype, return a strong reference to doctype-specific data.

source

pub fn into_document_ref(self) -> Option<NodeDataRef<DocumentData>>

If this node is a document, return a strong reference to document-specific data.

source§

impl NodeRef

source

pub fn serialize<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write,

Serialize this node and its descendants in HTML syntax to the given stream.

source

pub fn serialize_to_file<P>(&self, path: P) -> Result<(), Error>
where P: AsRef<Path>,

Serialize this node and its descendants in HTML syntax to a new file at the given path.

source§

impl NodeRef

source

pub fn new(data: NodeData) -> NodeRef

Create a new node.

source

pub fn new_element<I>(name: QualName, attributes: I) -> NodeRef
where I: IntoIterator<Item = (ExpandedName, Attribute)>,

Create a new element node.

source

pub fn new_text<T>(value: T) -> NodeRef
where T: Into<String>,

Create a new text node.

source

pub fn new_comment<T>(value: T) -> NodeRef
where T: Into<String>,

Create a new comment node.

source

pub fn new_processing_instruction<T1, T2>(target: T1, data: T2) -> NodeRef
where T1: Into<String>, T2: Into<String>,

Create a new processing instruction node.

source

pub fn new_doctype<T1, T2, T3>( name: T1, public_id: T2, system_id: T3, ) -> NodeRef
where T1: Into<String>, T2: Into<String>, T3: Into<String>,

Create a new doctype node.

source

pub fn new_document() -> NodeRef

Create a new document node.

source

pub fn text_contents(&self) -> String

Return the concatenation of all text nodes in this subtree.

source§

impl NodeRef

source

pub fn append(&self, new_child: NodeRef)

Append a new child to this node, after existing children.

The new child is detached from its previous position.

source

pub fn prepend(&self, new_child: NodeRef)

Prepend a new child to this node, before existing children.

The new child is detached from its previous position.

source

pub fn insert_after(&self, new_sibling: NodeRef)

Insert a new sibling after this node.

The new sibling is detached from its previous position.

source

pub fn insert_before(&self, new_sibling: NodeRef)

Insert a new sibling before this node.

The new sibling is detached from its previous position.

Methods from Deref<Target = Node>§

source

pub fn data(&self) -> &NodeData

Return a reference to this node’s node-type-specific data.

source

pub fn as_element(&self) -> Option<&ElementData>

If this node is an element, return a reference to element-specific data.

source

pub fn as_text(&self) -> Option<&RefCell<String>>

If this node is a text node, return a reference to its contents.

source

pub fn as_comment(&self) -> Option<&RefCell<String>>

If this node is a comment, return a reference to its contents.

source

pub fn as_doctype(&self) -> Option<&Doctype>

If this node is a document, return a reference to doctype-specific data.

source

pub fn as_document(&self) -> Option<&DocumentData>

If this node is a document, return a reference to document-specific data.

source

pub fn parent(&self) -> Option<NodeRef>

Return a reference to the parent node, unless this node is the root of the tree.

source

pub fn first_child(&self) -> Option<NodeRef>

Return a reference to the first child of this node, unless it has no child.

source

pub fn last_child(&self) -> Option<NodeRef>

Return a reference to the last child of this node, unless it has no child.

source

pub fn previous_sibling(&self) -> Option<NodeRef>

Return a reference to the previous sibling of this node, unless it is a first child.

source

pub fn next_sibling(&self) -> Option<NodeRef>

Return a reference to the next sibling of this node, unless it is a last child.

source

pub fn detach(&self)

Detach a node from its parent and siblings. Children are not affected.

To remove a node and its descendants, detach it and drop any strong reference to it.

Trait Implementations§

source§

impl Clone for NodeRef

source§

fn clone(&self) -> NodeRef

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for NodeRef

source§

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

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

impl Deref for NodeRef

§

type Target = Node

The resulting type after dereferencing.
source§

fn deref(&self) -> &Node

Dereferences the value.
source§

impl PartialEq for NodeRef

source§

fn eq(&self, other: &NodeRef) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for NodeRef

source§

fn serialize<S>( &self, serializer: &mut S, traversal_scope: TraversalScope, ) -> Result<(), Error>
where S: Serializer,

Take the serializer and call its methods to serialize this type. The type will dictate which methods are called and with what parameters.
source§

impl ToString for NodeRef

source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl Eq for NodeRef

Auto Trait Implementations§

§

impl Freeze for NodeRef

§

impl !RefUnwindSafe for NodeRef

§

impl !Send for NodeRef

§

impl !Sync for NodeRef

§

impl Unpin for NodeRef

§

impl !UnwindSafe for NodeRef

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<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.