Trait NodeExt

Source
pub trait NodeExt {
    // Required methods
    fn is_element<S: AsRef<str> + ?Sized>(&self, name: &S) -> bool;
    fn is_processing_instruction<S: AsRef<str> + ?Sized>(
        &self,
        name: &S,
    ) -> bool;
    fn element_attr_keys<'a>(
        &'a self,
    ) -> Result<Box<dyn Iterator<Item = String> + 'a>>;
    fn get_attr_value<S: AsRef<str> + ?Sized>(
        &self,
        name: &S,
    ) -> Result<Option<String>>;
    fn set_attr_value<S: AsRef<str> + ?Sized, V: AsRef<str> + ?Sized>(
        &self,
        name: &S,
        value: &V,
    ) -> Result<()>;
}
Available on crate feature markup5ever_rcdom only.
Expand description

Extensions for Node

Required Methods§

Source

fn is_element<S: AsRef<str> + ?Sized>(&self, name: &S) -> bool

Checks if the node is an element with the given name.

This function ignore namespaces.

Source

fn is_processing_instruction<S: AsRef<str> + ?Sized>(&self, name: &S) -> bool

Checks if the node is a processing instruction with the given name.

Source

fn element_attr_keys<'a>( &'a self, ) -> Result<Box<dyn Iterator<Item = String> + 'a>>

Returns an iterator over the attribute keys of the element node.

This function returns an empty iterator if the node is not an element. Only the local names of the attributes are returned, ignoring namespaces.

Source

fn get_attr_value<S: AsRef<str> + ?Sized>( &self, name: &S, ) -> Result<Option<String>>

Gets the value of the attribute with the given name.

This function returns Ok(None) if the node is not an element or if the attribute does not exist. This function ignores namespaces and only checks the local name of the attribute.

Source

fn set_attr_value<S: AsRef<str> + ?Sized, V: AsRef<str> + ?Sized>( &self, name: &S, value: &V, ) -> Result<()>

Sets the value of the attribute with the given name.

This function creates the attribute if it does not exist. This function ignores namespaces and only checks the local name of the attribute. Returns Ok(()) if the node is not an element.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl NodeExt for Node

Source§

fn is_element<S: AsRef<str> + ?Sized>(&self, name: &S) -> bool

Source§

fn is_processing_instruction<S: AsRef<str> + ?Sized>(&self, name: &S) -> bool

Source§

fn element_attr_keys<'a>( &'a self, ) -> Result<Box<dyn Iterator<Item = String> + 'a>>

Source§

fn get_attr_value<S: AsRef<str> + ?Sized>( &self, name: &S, ) -> Result<Option<String>>

Source§

fn set_attr_value<S: AsRef<str> + ?Sized, V: AsRef<str> + ?Sized>( &self, name: &S, value: &V, ) -> Result<()>

Implementors§