Struct kuchiki::NodeRef
[−]
[src]
pub struct NodeRef(pub Rc<Node>);
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.
Methods
impl NodeRef
[src]
ⓘImportant traits for Ancestorspub fn inclusive_ancestors(&self) -> Ancestors
[src]
Return an iterator of references to this node and its ancestors.
ⓘImportant traits for Ancestorspub fn ancestors(&self) -> Ancestors
[src]
Return an iterator of references to this node’s ancestors.
ⓘImportant traits for Rev<I>pub fn inclusive_preceding_siblings(&self) -> Rev<Siblings>
[src]
Return an iterator of references to this node and the siblings before it.
ⓘImportant traits for Rev<I>pub fn preceding_siblings(&self) -> Rev<Siblings>
[src]
Return an iterator of references to this node’s siblings before it.
ⓘImportant traits for Siblingspub fn inclusive_following_siblings(&self) -> Siblings
[src]
Return an iterator of references to this node and the siblings after it.
ⓘImportant traits for Siblingspub fn following_siblings(&self) -> Siblings
[src]
Return an iterator of references to this node’s siblings after it.
ⓘImportant traits for Siblingspub fn children(&self) -> Siblings
[src]
Return an iterator of references to this node’s children.
ⓘImportant traits for Descendantspub fn inclusive_descendants(&self) -> Descendants
[src]
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()
.
ⓘImportant traits for Descendantspub fn descendants(&self) -> Descendants
[src]
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()
.
ⓘImportant traits for Traversepub fn traverse_inclusive(&self) -> Traverse
[src]
Return an iterator of the start and end edges of this node and its descendants, in tree order.
ⓘImportant traits for Traversepub fn traverse(&self) -> Traverse
[src]
Return an iterator of the start and end edges of this node’s descendants, in tree order.
pub fn select(
&self,
selectors: &str
) -> Result<Select<Elements<Descendants>>, ()>
[src]
&self,
selectors: &str
) -> Result<Select<Elements<Descendants>>, ()>
Return an iterator of the inclusive descendants element that match the given selector list.
pub fn select_first(
&self,
selectors: &str
) -> Result<NodeDataRef<ElementData>, ()>
[src]
&self,
selectors: &str
) -> Result<NodeDataRef<ElementData>, ()>
Return the first inclusive descendants element that match the given selector list.
impl NodeRef
[src]
pub fn into_element_ref(self) -> Option<NodeDataRef<ElementData>>
[src]
If this node is an element, return a strong reference to element-specific data.
pub fn into_text_ref(self) -> Option<NodeDataRef<RefCell<String>>>
[src]
If this node is a text node, return a strong reference to its contents.
pub fn into_comment_ref(self) -> Option<NodeDataRef<RefCell<String>>>
[src]
If this node is a comment, return a strong reference to its contents.
pub fn into_doctype_ref(self) -> Option<NodeDataRef<Doctype>>
[src]
If this node is a doctype, return a strong reference to doctype-specific data.
pub fn into_document_ref(self) -> Option<NodeDataRef<DocumentData>>
[src]
If this node is a document, return a strong reference to document-specific data.
impl NodeRef
[src]
pub fn serialize<W: Write>(&self, writer: &mut W) -> Result<()>
[src]
Serialize this node and its descendants in HTML syntax to the given stream.
pub fn serialize_to_file<P: AsRef<Path>>(&self, path: P) -> Result<()>
[src]
Serialize this node and its descendants in HTML syntax to a new file at the given path.
impl NodeRef
[src]
pub fn new(data: NodeData) -> NodeRef
[src]
Create a new node.
pub fn new_element<I>(name: QualName, attributes: I) -> NodeRef where
I: IntoIterator<Item = (ExpandedName, Attribute)>,
[src]
I: IntoIterator<Item = (ExpandedName, Attribute)>,
Create a new element node.
pub fn new_text<T: Into<String>>(value: T) -> NodeRef
[src]
Create a new text node.
pub fn new_comment<T: Into<String>>(value: T) -> NodeRef
[src]
Create a new comment node.
pub fn new_processing_instruction<T1, T2>(target: T1, data: T2) -> NodeRef where
T1: Into<String>,
T2: Into<String>,
[src]
T1: Into<String>,
T2: Into<String>,
Create a new processing instruction node.
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>,
[src]
name: T1,
public_id: T2,
system_id: T3
) -> NodeRef where
T1: Into<String>,
T2: Into<String>,
T3: Into<String>,
Create a new doctype node.
pub fn new_document() -> NodeRef
[src]
Create a new document node.
pub fn text_contents(&self) -> String
[src]
Return the concatenation of all text nodes in this subtree.
impl NodeRef
[src]
pub fn append(&self, new_child: NodeRef)
[src]
Append a new child to this node, after existing children.
The new child is detached from its previous position.
pub fn prepend(&self, new_child: NodeRef)
[src]
Prepend a new child to this node, before existing children.
The new child is detached from its previous position.
pub fn insert_after(&self, new_sibling: NodeRef)
[src]
Insert a new sibling after this node.
The new sibling is detached from its previous position.
pub fn insert_before(&self, new_sibling: NodeRef)
[src]
Insert a new sibling before this node.
The new sibling is detached from its previous position.
Methods from Deref<Target = Node>
pub fn data(&self) -> &NodeData
[src]
Return a reference to this node’s node-type-specific data.
pub fn as_element(&self) -> Option<&ElementData>
[src]
If this node is an element, return a reference to element-specific data.
pub fn as_text(&self) -> Option<&RefCell<String>>
[src]
If this node is a text node, return a reference to its contents.
pub fn as_comment(&self) -> Option<&RefCell<String>>
[src]
If this node is a comment, return a reference to its contents.
pub fn as_doctype(&self) -> Option<&Doctype>
[src]
If this node is a document, return a reference to doctype-specific data.
pub fn as_document(&self) -> Option<&DocumentData>
[src]
If this node is a document, return a reference to document-specific data.
pub fn parent(&self) -> Option<NodeRef>
[src]
Return a reference to the parent node, unless this node is the root of the tree.
pub fn first_child(&self) -> Option<NodeRef>
[src]
Return a reference to the first child of this node, unless it has no child.
pub fn last_child(&self) -> Option<NodeRef>
[src]
Return a reference to the last child of this node, unless it has no child.
pub fn previous_sibling(&self) -> Option<NodeRef>
[src]
Return a reference to the previous sibling of this node, unless it is a first child.
pub fn next_sibling(&self) -> Option<NodeRef>
[src]
Return a reference to the previous sibling of this node, unless it is a last child.
pub fn detach(&self)
[src]
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
impl Serialize for NodeRef
[src]
fn serialize<S: Serializer>(
&self,
serializer: &mut S,
traversal_scope: TraversalScope
) -> Result<()>
[src]
&self,
serializer: &mut S,
traversal_scope: TraversalScope
) -> Result<()>
Take the serializer and call its methods to serialize this type. The type will dictate which methods are called and with what parameters. Read more
impl ToString for NodeRef
[src]
impl Clone for NodeRef
[src]
fn clone(&self) -> NodeRef
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for NodeRef
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Deref for NodeRef
[src]
type Target = Node
The resulting type after dereferencing.
fn deref(&self) -> &Node
[src]
Dereferences the value.