Struct Node

Source
pub struct Node<'a> { /* private fields */ }
Expand description

A single node of an HTML document. Nodes may be HTML elements, comments, or text nodes.

Implementations§

Source§

impl<'a> Node<'a>

Source

pub fn new(document: &'a Document, index: usize) -> Option<Node<'a>>

Create a Node referring to the indexth Node of a document.

Source

pub fn index(&self) -> usize

Get the index of this Node in its Document.

Source

pub fn raw(&self) -> &'a Raw

Obtain the inner representation of this Node.

Source

pub fn data(&self) -> &'a Data

Get the text node, HTML element, or comment from a Node.

Source

pub fn name(&self) -> Option<&'a str>

Get the name of a Node if it is an HTML element, or None otherwise.

Source

pub fn attr(&self, name: &str) -> Option<&'a str>

Get the value of the attribute name from a Node representing a HTML element.

Source

pub fn attrs(&self) -> impl Iterator<Item = (&'a str, &'a str)>

Get an iterator over the names and values of attributes of the Element. Returns an empty iterator for non Element nodes.

Source

pub fn parent(&self) -> Option<Node<'a>>

Source

pub fn prev(&self) -> Option<Node<'a>>

Source

pub fn next(&self) -> Option<Node<'a>>

Source

pub fn first_child(&self) -> Option<Node<'a>>

Source

pub fn last_child(&self) -> Option<Node<'a>>

Source

pub fn text(&self) -> String

Get the combined textual content of a Node and all of its children.

Source

pub fn html(&self) -> String

Serialize a Node to an HTML string.

Source

pub fn inner_html(&self) -> String

Serialize a Node’s children to an HTML string.

Source

pub fn find<P: Predicate>(&self, predicate: P) -> Find<'a, P>

Search for Nodes fulfilling predicate in the descendants of a Node.

Source

pub fn is<P: Predicate>(&self, p: P) -> bool

Evaluate a predicate on this Node.

Source

pub fn as_text(&self) -> Option<&'a str>

Get the text of a text Node, or None if the node is not text.

Source

pub fn as_comment(&self) -> Option<&'a str>

Get the text of a comment Node, or None if the node is not a comment.

Source

pub fn children(&self) -> Children<'a>

Construct an iterator over a Node’s child Nodes.

Source

pub fn descendants(&self) -> Descendants<'a>

Construct an iterator over a Node’s descendant (transitive children) Nodes.

Trait Implementations§

Source§

impl<'a> Clone for Node<'a>

Source§

fn clone(&self) -> Node<'a>

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<'a> Debug for Node<'a>

Source§

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

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

impl<'a> PartialEq for Node<'a>

Source§

fn eq(&self, other: &Node<'a>) -> 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<'a> Serialize for Node<'a>

Source§

fn serialize<S: Serializer>( &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.
Source§

impl<'a> Copy for Node<'a>

Source§

impl<'a> Eq for Node<'a>

Source§

impl<'a> StructuralPartialEq for Node<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Node<'a>

§

impl<'a> !RefUnwindSafe for Node<'a>

§

impl<'a> !Send for Node<'a>

§

impl<'a> !Sync for Node<'a>

§

impl<'a> Unpin for Node<'a>

§

impl<'a> !UnwindSafe for Node<'a>

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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,

Source§

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

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.