HtmlElement

Struct HtmlElement 

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

A structure representing HTML element.

Implementations§

Source§

impl HtmlElement

Source

pub fn new(name: &str) -> Self

Creates a new HTML element with specified tag name.

Source

pub fn no_indent(self) -> Self

Source

pub fn hide_closing_tag(self) -> Self

Source

pub fn always_expand(self) -> Self

Source

pub fn attribute<N, V>(self, name: N, value: V) -> Self
where N: ToString, V: ToString,

Sets an attribute of the HTML element.

Source

pub fn set_attribute<N, V>(&mut self, name: N, value: V)
where N: ToString, V: ToString,

Sets an attribute of the HTML element.

Source

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

Sets a class attribute of the HTML element.

Source

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

Sets a class attribute of the HTML element.

Source

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

Sets a style attribute of the HTML element.

Source

pub fn set_style(&mut self, style: &str)

Sets a style attribute of the HTML element.

Source

pub fn child(self, child: impl Into<HtmlElement>) -> Self

Adds a child element.

Source

pub fn add_child(&mut self, child: impl Into<HtmlElement>)

Adds a child element.

Source

pub fn opt_child(self, opt_child: Option<HtmlElement>) -> Self

Adds an optional child element.

Source

pub fn add_opt_child(&mut self, opt_child: Option<HtmlElement>)

Adds an optional child element.

Source

pub fn children(self, children: &[HtmlElement]) -> Self

Adds multiple children elements.

Source

pub fn add_children(&mut self, children: &[HtmlElement])

Adds multiple children elements.

Source

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

Sets the content of the HTML element.

Source

pub fn set_content(&mut self, content: &str)

Sets the content of the HTML element.

Source§

impl HtmlElement

Implementation of commonly used HTML elements.

Source

pub fn h1(content: &str) -> Self

Creates <h1> HTML element. The section heading level 1 element.

§Example
let h = HtmlElement::h1("Heading level 1");
assert_eq!("<h1>Heading level 1</h1>", h.to_string());
Source

pub fn h2(content: &str) -> Self

Creates <h2> HTML element. The section heading level 2 element.

§Example
let h = HtmlElement::h2("Heading level 2");
assert_eq!("<h2>Heading level 2</h2>", h.to_string());
Source

pub fn h3(content: &str) -> Self

Creates <h3> HTML element. The section heading level 3 element.

§Example
let h = HtmlElement::h3("Heading level 3");
assert_eq!("<h3>Heading level 3</h3>", h.to_string());
Source

pub fn h4(content: &str) -> Self

Creates <h4> HTML element. The section heading level 4 element.

§Example
let h = HtmlElement::h4("Heading level 4");
assert_eq!("<h4>Heading level 4</h4>", h.to_string());
Source

pub fn h5(content: &str) -> Self

Creates <h5> HTML element. The section heading level 5 element.

§Example
let h = HtmlElement::h5("Heading level 5");
assert_eq!("<h5>Heading level 5</h5>", h.to_string());
Source

pub fn h6(content: &str) -> Self

Creates <h6> HTML element. The section heading level 6 element.

§Example
let h = HtmlElement::h6("Heading level 6");
assert_eq!("<h6>Heading level 6</h6>", h.to_string());
Source

pub fn br() -> Self

Creates <br> HTML element. The line break element.

§Example
let br = HtmlElement::br();
assert_eq!("<br/>", br.to_string());
Source

pub fn div() -> Self

Creates <div> HTML element. The content division element.

§Example
let div = HtmlElement::div();
assert_eq!("<div></div>", div.to_string());
Source

pub fn span() -> Self

Creates <span> HTML element. The content span element.

§Example
let span = HtmlElement::span();
assert_eq!("<span></span>", span.to_string());

Trait Implementations§

Source§

impl Clone for HtmlElement

Source§

fn clone(&self) -> HtmlElement

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 HtmlElement

Source§

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

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

impl Display for HtmlElement

Source§

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

Implements Display for HtmlElement.

Source§

impl From<&HtmlBodyElement> for HtmlElement

Source§

fn from(value: &HtmlBodyElement) -> Self

Converts a reference to HtmlBodyElement into HtmlElement.

Source§

impl From<HtmlBodyElement> for HtmlElement

Source§

fn from(value: HtmlBodyElement) -> Self

Source§

impl From<HtmlHeadElement> for HtmlElement

Source§

fn from(value: HtmlHeadElement) -> Self

Converts to this type from the input type.
Source§

impl From<HtmlLinkElement> for HtmlElement

Source§

fn from(value: HtmlLinkElement) -> Self

Converts to this type from the input type.
Source§

impl From<HtmlStyleElement> for HtmlElement

Source§

fn from(value: HtmlStyleElement) -> Self

Converts to this type from the input type.
Source§

impl From<SvgDocument> for HtmlElement

Source§

fn from(value: SvgDocument) -> Self

Creates HtmlElement from SvgDocument.

Source§

impl ToText for HtmlElement

Source§

fn to_text(&self, offset: usize, indent: usize) -> String

Converts HtmlElement into text with specified offset and indent.

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