Element

Struct Element 

Source
pub struct Element { /* private fields */ }

Implementations§

Source§

impl Element

Source

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

This function returns an empty element.

Examples found in repository?
examples/sample_generator.rs (line 4)
3fn main() {
4    let mut el = Element::new("Div", false);
5    el.add_class("TestClass");
6    el.add_class("AnotherClass");
7    let mut h1 = Element::new("H1", false);
8    h1.add_text("This is a heading!!");
9    el.add_element(h1);
10    el.add_comment("A Comment");
11    let mut btn = Element::new("Button", true);
12    btn.add_attribute("text", "This is a Button");
13    el.add_element(btn);
14    println!("{}", el)
15}
Source

pub fn from( name: &str, self_closing: bool, attributes: HashMap<String, String>, children: Vec<HtmlData>, ) -> Self

This function returns an element from the given data

Source

pub fn set_id(&mut self, id: &str)

Set the ID of the element.

Source

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

Add a class to the element.

Examples found in repository?
examples/sample_generator.rs (line 5)
3fn main() {
4    let mut el = Element::new("Div", false);
5    el.add_class("TestClass");
6    el.add_class("AnotherClass");
7    let mut h1 = Element::new("H1", false);
8    h1.add_text("This is a heading!!");
9    el.add_element(h1);
10    el.add_comment("A Comment");
11    let mut btn = Element::new("Button", true);
12    btn.add_attribute("text", "This is a Button");
13    el.add_element(btn);
14    println!("{}", el)
15}
Source

pub fn add_element(&mut self, element: Element)

Add a child element to the element.

Examples found in repository?
examples/sample_generator.rs (line 9)
3fn main() {
4    let mut el = Element::new("Div", false);
5    el.add_class("TestClass");
6    el.add_class("AnotherClass");
7    let mut h1 = Element::new("H1", false);
8    h1.add_text("This is a heading!!");
9    el.add_element(h1);
10    el.add_comment("A Comment");
11    let mut btn = Element::new("Button", true);
12    btn.add_attribute("text", "This is a Button");
13    el.add_element(btn);
14    println!("{}", el)
15}
Source

pub fn add_children(&mut self, children: &mut Vec<HtmlData>)

Append a vector of HTML data into the element

Source

pub fn add_comment(&mut self, comment: &str)

Add a comment inside the element.

Examples found in repository?
examples/sample_generator.rs (line 10)
3fn main() {
4    let mut el = Element::new("Div", false);
5    el.add_class("TestClass");
6    el.add_class("AnotherClass");
7    let mut h1 = Element::new("H1", false);
8    h1.add_text("This is a heading!!");
9    el.add_element(h1);
10    el.add_comment("A Comment");
11    let mut btn = Element::new("Button", true);
12    btn.add_attribute("text", "This is a Button");
13    el.add_element(btn);
14    println!("{}", el)
15}
Source

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

Add plain text inside teh element.

Examples found in repository?
examples/sample_generator.rs (line 8)
3fn main() {
4    let mut el = Element::new("Div", false);
5    el.add_class("TestClass");
6    el.add_class("AnotherClass");
7    let mut h1 = Element::new("H1", false);
8    h1.add_text("This is a heading!!");
9    el.add_element(h1);
10    el.add_comment("A Comment");
11    let mut btn = Element::new("Button", true);
12    btn.add_attribute("text", "This is a Button");
13    el.add_element(btn);
14    println!("{}", el)
15}
Source

pub fn add_attribute(&mut self, attribute: &str, value: &str)

Add an attribute to the element

Examples found in repository?
examples/sample_generator.rs (line 12)
3fn main() {
4    let mut el = Element::new("Div", false);
5    el.add_class("TestClass");
6    el.add_class("AnotherClass");
7    let mut h1 = Element::new("H1", false);
8    h1.add_text("This is a heading!!");
9    el.add_element(h1);
10    el.add_comment("A Comment");
11    let mut btn = Element::new("Button", true);
12    btn.add_attribute("text", "This is a Button");
13    el.add_element(btn);
14    println!("{}", el)
15}

Trait Implementations§

Source§

impl Display for Element

Source§

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

Formats the value using the given formatter. Read more

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