pub struct Element { /* private fields */ }Implementations§
Source§impl Element
impl Element
Sourcepub fn new(name: &str, self_closing: bool) -> Self
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}Sourcepub fn from(
name: &str,
self_closing: bool,
attributes: HashMap<String, String>,
children: Vec<HtmlData>,
) -> Self
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
Sourcepub fn add_class(&mut self, class: &str)
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}Sourcepub fn add_element(&mut self, element: Element)
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}Sourcepub fn add_children(&mut self, children: &mut Vec<HtmlData>)
pub fn add_children(&mut self, children: &mut Vec<HtmlData>)
Append a vector of HTML data into the element
Sourcepub fn add_comment(&mut self, comment: &str)
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}Sourcepub fn add_text(&mut self, text: &str)
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}Sourcepub fn add_attribute(&mut self, attribute: &str, value: &str)
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§
Auto Trait Implementations§
impl Freeze for Element
impl RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl UnwindSafe for Element
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more