DomNode

Struct DomNode 

Source
pub struct DomNode(/* private fields */);
Expand description

Based on https://docs.rs/rctree/latest/rctree/struct.Node.html

Implementations§

Source§

impl DomNode

Source

pub fn new(kind: DomNodeKind) -> DomNode

Creates a new node

Source

pub fn create_element(tag: impl Into<String>) -> DomNode

Source

pub fn create_element_with_attributes( tag: impl Into<String>, attributes: HashMap<String, String>, ) -> DomNode

Source

pub fn create_text(text: impl Into<String>) -> DomNode

Source

pub fn get_attribute(&self, attribute: &str) -> Option<String>

Source

pub fn set_attribute(&mut self, key: &str, value: &str)

Source

pub fn downgrade(&self) -> WeakDomNode

Returns a weak referece to a node.

Source

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

Returns a parent node, unless this node is the root of the tree.

§Panics

Panics if the node is currently mutably borrowed.

Source

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

Returns a first child of this node, unless it has no child.

§Panics

Panics if the node is currently mutably borrowed.

Source

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

Returns a last child of this node, unless it has no child.

§Panics

Panics if the node is currently mutably borrowed.

Source

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

Returns the previous sibling of this node, unless it is a first child.

§Panics

Panics if the node is currently mutably borrowed.

Source

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

Returns the next sibling of this node, unless it is a last child.

§Panics

Panics if the node is currently mutably borrowed.

Source

pub fn kind(&self) -> Ref<'_, DomNodeKind>

Source

pub fn kind_mut(&self) -> RefMut<'_, DomNodeKind>

Source

pub fn ancestors(&self) -> Ancestors

Returns an iterator of nodes to this node and its ancestors.

Includes the current node.

Source

pub fn preceding_siblings(&self) -> PrecedingSiblings

Returns an iterator of nodes to this node and the siblings before it.

Includes the current node.

Source

pub fn following_siblings(&self) -> FollowingSiblings

Returns an iterator of nodes to this node and the siblings after it.

Includes the current node.

Source

pub fn children(&self) -> Children

Returns an iterator of nodes to this node’s children.

§Panics

Panics if the node is currently mutably borrowed.

Source

pub fn has_children(&self) -> bool

Returns true if this node has children nodes.

§Panics

Panics if the node is currently mutably borrowed.

Source

pub fn descendants(&self) -> Descendants

Returns an iterator of nodes to this node and its descendants, in tree order.

Includes the current node.

Source

pub fn traverse(&self) -> Traverse

Returns an iterator of nodes to this node and its descendants, in tree order.

Source

pub fn sanitize_children(&mut self)

Remove empty tags or invalid html in a way that makes sense

Source

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

Source

pub fn get_element_by_id(&self, id: &str) -> Option<DomNode>

Source

pub fn inner_text(&self) -> String

Returns the text content of this node and all its descendants.

Source

pub fn detach(&self)

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

§Panics

Panics if the node or one of its adjoining nodes is currently borrowed.

Source

pub fn append_child(&self, new_child: impl Into<IterableNodes>)

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

§Panics

Panics if the node, the new child, or one of their adjoining nodes is currently borrowed.

Source

pub fn prepend(&self, new_child: DomNode)

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

§Panics

Panics if the node, the new child, or one of their adjoining nodes is currently borrowed.

Source

pub fn insert_after(&self, new_sibling: DomNode)

Inserts a new sibling after this node.

§Panics

Panics if the node, the new sibling, or one of their adjoining nodes is currently borrowed.

Source

pub fn insert_before(&self, new_sibling: DomNode)

Inserts a new sibling before this node.

§Panics

Panics if the node, the new sibling, or one of their adjoining nodes is currently borrowed.

Source

pub fn from_html(html: Html) -> Option<Self>

Trait Implementations§

Source§

impl Clone for DomNode

Cloning a Node only increments a reference count. It does not copy the data.

Source§

fn clone(&self) -> Self

Returns a duplicate 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 DomNode

Source§

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

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

impl Display for DomNode

Source§

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

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

impl From<DomNode> for Html

Source§

fn from(value: DomNode) -> Self

Converts to this type from the input type.
Source§

impl From<DomNode> for IterableNodes

Source§

fn from(value: DomNode) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<DomNode> for IterableNodes

Source§

fn from_iter<T: IntoIterator<Item = DomNode>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for DomNode

Source§

fn eq(&self, other: &DomNode) -> 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.

Auto Trait Implementations§

§

impl Freeze for DomNode

§

impl !RefUnwindSafe for DomNode

§

impl !Send for DomNode

§

impl !Sync for DomNode

§

impl Unpin for DomNode

§

impl !UnwindSafe for DomNode

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.