Struct html_page::Element

source ·
pub struct Element { /* private fields */ }
Expand description

An HTML element.

The element has a Tag, possibly some attributes, and possibly some children. It may also have a location: this is used when the element is constructed by parsing some input value.

Implementations§

source§

impl Element

source

pub fn new(tag: Tag) -> Self

Create a new element, with a given tag.

source

pub fn with_location(self, line: usize, col: usize) -> Self

Set the location of an element in a source file.

source

pub fn with_child(self, child: Element) -> Self

Append a child element, when constructing.

source

pub fn with_text(self, child: &str) -> Self

Append a text child, when constructing.

source

pub fn with_attribute(self, name: &str, value: &str) -> Self

Set an attribute when creating an element.

source

pub fn with_boolean_attribute(self, name: &str) -> Self

Set a boolean attribute when creating an element.

source

pub fn with_class(self, class: &str) -> Self

Add a class when creating an element.

source

pub fn tag(&self) -> Tag

Return the Tag of the element.

source

pub fn location(&self) -> Option<(usize, usize)>

Return the location of the element.

source

pub fn attributes(&self) -> impl Iterator<Item = &str>

Return an iterator over the names of the attributes of an element.

source

pub fn attribute(&self, name: &str) -> Option<&AttributeValue>

Return the value of an attribute, if the attribute is set. Otherwise, return None.

source

pub fn attribute_value(&self, name: &str) -> Option<&str>

Return the value of an attribute as text, if the attribute is set. Otherwise, return None.

source

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

Set a key/value attribute. If the attribute was already set, change the value it has.

source

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

Set a boolean attribute.

source

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

Remove an attribute, which can be key/value or boolean.

source

pub fn classes(&self) -> impl Iterator<Item = &str>

Return current classes set directly for this element.

source

pub fn has_class(&self, wanted: &str) -> bool

Does the element have a class set directly?

source

pub fn add_class(&mut self, class: &str)

Add a class to the element. This does not replace existing classes.

source

pub fn push_text(&mut self, text: &str)

Append text to element. It will be escaped, if needed, when the element is serialized.

source

pub fn push_child(&mut self, child: Element)

Append a child element to this element.

source

pub fn clear_children(&mut self)

Remove all children.

source

pub fn push_html(&mut self, html: &str)

Append HTML to element. It will NOT be escaped, when the element is serialized. This is an easy to inject arbitrary junk into the HTML. No validation is done. You should avoid this if you can.

source

pub fn serialize(&self) -> String

Serialize an element into HTML.

source

pub fn plain_text(&self) -> String

Return all the textual content in an element and its children. This does not include attributes.

Trait Implementations§

source§

impl Clone for Element

source§

fn clone(&self) -> Element

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 Element

source§

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

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

impl Display for Element

source§

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

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

impl PartialEq for Element

source§

fn eq(&self, other: &Element) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Element

source§

impl StructuralPartialEq for Element

Auto Trait Implementations§

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

§

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§

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

§

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

§

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.