Struct Node

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

Contains information about opening and corresponding closing tags. It also can contain the value of the text between opening and closing tags if there are no children. Otherwise, if there are children mixed with text then each text chunk is separated in it’s own node with other children in order they appear in the code.

Implementations§

Source§

impl Node

Source

pub fn new() -> Self

Create new empty node with no children nor tags.

Source

pub fn from_html( html: &str, settings: &LoadSettings, ) -> Result<Option<Node>, Error>

Load node tree from HTML string.

The root node has no start, end or text elements. It does have only children in it. When passing empty code, None will be returned. If there is an error parsing the HTML, then this function will fail and return the error type that occurred.

Source

pub fn from_html_first(html: &str, settings: &LoadSettings) -> Option<Self>

Load the first node from HTML string without wrapping node to the tree with root (empty first node). Just return the exact single node.

§Failures

None is returned if string does not contain any node (is empty).

Source

pub fn start(&self) -> &Option<OpeningTag>

Start tag information.

Source

pub fn end(&self) -> Option<&str>

End tag information.

Source

pub fn text(&self) -> Option<&str>

Text that appears between opening and closing tags.

Source

pub fn children(&self) -> &Children

Children tags of this node.

Source

pub fn tag_name(&self) -> Option<&str>

The name of the tag that is represented by the node.

Source

pub fn attributes(&self) -> Option<&Vec<Attribute>>

Start tag attributes.

Source

pub fn attribute_by_name(&self, key: &str) -> Option<&Attribute>

Find attribute by it’s name.

Source

pub fn put_attribute(&mut self, attr: Attribute) -> Result<(), Attribute>

Try saving given attribute in this node.

§Failure

If this attribute is already present then this function will not change it. If you need to overwrite the attribute anyway use [overwrite_attribute].

Source

pub fn overwrite_attribute(&mut self, attr: Attribute)

Save this attribute in the node. If it is already present then overwrite it.

Source

pub fn children_fetch(&self) -> ChildrenFetch<'_>

Get children fetcher for this node to find children that apply to some criteria.

Source

pub fn children_fetch_mut(&mut self) -> ChildrenFetchMut<'_>

Source

pub fn to_string(&self) -> String

Convert this node and all it’s children into HTML string.

Source

pub fn change_name(&mut self, name: &str)

Change name of opening and closing tags (if any).

Source

pub fn change_opening_name(&mut self, name: &str)

Change the name of only opening tag if it exists.

Source

pub fn change_closing_name(&mut self, name: &str)

Change the name of only closing tag if it exists.

Source

pub fn children_mut(&mut self) -> &mut Children

Mutable access to array of node’s children.

Source

pub fn clone_without_children(&self) -> Self

Clone this node without cloning children leaving new node with empty children list.

Source

pub fn wrap_to_root(self) -> Result<Self, Self>

Try wrapping this node into root. This makes it possible to use this node as individual tree.

It is required for trees to start with empty node only with children. Many functions rely on this rule. For example, Fetch functions filter data only in children ignoring parent attributes and data.

§Failures

If this node already is root it is returned back in Err.

Source

pub fn is_root(&self) -> bool

Check whether this node is the root of the tree.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

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 Node

Source§

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

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

impl Default for Node

Source§

fn default() -> Node

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

impl From<Node> for NodeAccess

Source§

fn from(node: Node) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Node

Source§

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

Auto Trait Implementations§

§

impl Freeze for Node

§

impl RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnwindSafe for Node

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.